Subselect in insert without additional API call #2190
-
Environment
Description of issueFor the following example tables: create table recipe (
recipe_id serial primary key,
recipe_name varchar(255) unique not null
);
create table ingredient (
ingredient_id serial primary key,
ingredient_name varchar(255) unique
);
create table recipe_ingredient (
recipe_id int references recipe(recipe_id) not null,
ingredient_id int references ingredient(ingredient_id) not null,
record_status int not null default 0,
primary key (recipe_id, ingredient_id)
); I would like to execute the following as a single call to Postgrest: insert into recipe_ingredient (recipe_id, ingredient_id) values ((select recipe_id from recipe where recipe_name = 'Lasagne'), (select ingredient_id from ingredient where ingredient_name = 'Cheese')); Is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Not exactly like that, but in #818 we discussed doing something like: POST /recipe?columns=id,ingredient(id)
[
{"id": 1, "ingredient": [{"id": 13}]}
] That would detect the m2m relationship and automatically create the junction table( |
Beta Was this translation helpful? Give feedback.
-
Thanks the for the response. I'm trying to map this solution to what I'm doing.
Hope that makes sense. |
Beta Was this translation helpful? Give feedback.
-
There are a couple of different ways to do this:
|
Beta Was this translation helpful? Give feedback.
There are a couple of different ways to do this: