因此Postgres中似乎没有DELETE JOIN
,所以我尝试使用USING
:
DELETE FROM
creator.list_items li
USING
creator.lists l
USING
item_instances ii
WHERE
li.list_id = l._id
AND
li.item_instance_id = ii._id
AND
ii.item_id IN ($1:list)
AND
l._id = $2
AND
l.account_id = $3
但这只会给我错误:
ERROR: syntax error at or near "USING"
LINE 5: USING
我的原始查询:
DELETE
li
FROM
creator.list_items li
JOIN
creator.lists l
ON
li.list_id = l._id
JOIN
item_instances ii
ON
li.item_instance_id = ii._id
WHERE
ii.item_id IN ($1:list)
AND
l._id = $2
AND
l.account_id = $3
答案 0 :(得分:1)
您实际上可以在JOIN
子句中使用USING
:
DELETE FROM
creator.list_items li
USING creator.lists l JOIN
item_instances ii
ON li.list_id = l._id
WHERE li.item_instance_id = ii._id AND
ii.item_id IN ($1:list) AND
l._id = $2 AND
l.account_id = $3;
答案 1 :(得分:0)
我正在运行的查询:
DELETE FROM
creator.list_items li
USING
creator.lists l
WHERE
li.item_instance_id
IN
(
SELECT
_id
FROM
creator.item_instances
WHERE
item_id IN ($1:list)
)
AND
li.list_id = $2
AND
li.list_id = l._id
AND
l.account_id = $3