如何在以下函数中分解出常见的 SELECT 语句?
CREATE OR REPLACE PROCEDURE delete_comment(cid integer[]) AS $$
BEGIN
DELETE FROM comment_tree_path
WHERE descendant IN (SELECT descendant
FROM comment_tree_path
WHERE ancestor = ANY(cid));
DELETE FROM comment
WHERE comment_id IN (SELECT descendant
FROM comment_tree_path
WHERE ancestor = ANY(cid));
END;
$$ LANGUAGE plpgsql;
您还可以使用 CTE:
用于
SELECT array_agg(...) INTO
将目标列表拉入本地数组变量,然后将其作为参数传递给您DELETE
的 s 使用= ANY
: