I have two tables:
CREATE TABLE public.test
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY
)
and
CREATE TABLE public.test2
(
id integer,
test_id integer
)
Table test2
has two rows (1, null) and (2, null). Table test
has nothing. Now I want to fill test_id by creating new rows in test
. I nead a new entity each time so that I will have (1, 1), (2, 2), etc. I try to prepare update
query with an insert
statement but I don't understand how to do it. This is what I try:
update t2 set t2.test_id = t.id
from test2 t2 full join (INSERT INTO test(id) VALUES (default) RETURNING id) t on t2.test_id = t.id
but I get the following:
ERROR: syntax error at or near "INTO"
LINE 2: from test2 t2 full join (INSERT INTO test(id) VALUES (defaul...
^
SQL state: 42601
Character: 65
Can I create the query I want somehow?