gpt4 book ai didi

sql - 有一个名为...的列无法从这部分查询子查询中引用

转载 作者:行者123 更新时间:2023-11-29 11:44:24 25 4
gpt4 key购买 nike

 WITH upt as (
UPDATE backend."orders" SET "statusId" = 5
WHERE "userId" IN (177962,88265) and "statusId" IN (0,1,2,3,4) RETURNING *
)
INSERT INTO __test_result(orderid) VALUES ((SELECT orderid FROM upt))

需要更新和记录数据,得到这个错误

ERROR: column "orderid" does not exist Hint: There is a column named 
"orderid" in table "__test_result", but it cannot be referenced from this part of the query.

我怎样才能在表中插入所有“upt”行?它必须看起来

"upt.orderid","jsonb for that orderid"

对于每个订单,jsonb 必须从具有相同 orderid 的“upt”列创建

最佳答案

如果你想使用 select 作为插入(多行)的来源,不要使用 values 子句,直接使用 select:插入 .. 选择 ...

所以在你的情况下:

WITH upt as (
UPDATE backend."orders"
SET "statusId" = 5
WHERE "userId" IN (177962,88265)
and "statusId" IN (0,1,2,3,4)
RETURNING *
)
INSERT INTO __test_result(orderid)
SELECT orderid
FROM upt;

关于sql - 有一个名为...的列无法从这部分查询子查询中引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50739033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com