For my task i need to add a main entry and then add some additional, using the id of the added record. Now i use request with "returning id":
with rows as (
insert into "Contact"(name, gender, city, birthdate)
values
('Name', 1, 'City', '2000-02-03')
returning id
)
insert into "Education"(user_id, place, degree, endyear)
select id , 'some_place', 'some_state', 1990 from rows
This way I can add one additional entry, but I need several. If I try to do the second insert query - postgre loses relation "rows"
with rows as (
insert into "Contact"(name, gender, city, birthdate)
values
('Name', 1, 'City', '2000-02-03')
returning id
)
insert into "Education"(user_id, place, degree, endyear)
select id , 'some_place', 'some_state', 1990 from rows
insert into "Status"(user_id, status)
select id , 'val' from rows
ERROR: relation "rows" does not exist
LINE 11: select id , 'val' from rows
^
SQL state: 42P01
Character: 373
is there any way to fix this?