【发布时间】:2020-09-07 10:04:55
【问题描述】:
我有两张桌子:
CREATE TABLE public.test
(
id integer NOT NULL GENERATED ALWAYS AS IDENTITY
)
和
CREATE TABLE public.test2
(
id integer,
test_id integer
)
表test2 有两行(1,null)和(2,null)。表test 什么都没有。现在我想通过在test 中创建新行来填充 test_id。我每次都需要一个新实体,以便拥有 (1, 1)、(2, 2) 等。我尝试使用 insert 语句准备 update 查询,但我不明白该怎么做.这是我尝试的:
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
但我得到以下信息:
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
我能以某种方式创建我想要的查询吗?
【问题讨论】:
-
test中真的只有一列,还是还有其他列? -
这只是为了测试
标签: sql postgresql sql-update sql-insert bulkupdate