How can I factor out the common SELECT statement in the following function?
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;