Re: COMMIT within function? - Mailing list pgsql-general

From Pierre-Frédéric Caillaud
Subject Re: COMMIT within function?
Date
Msg-id opsht78502cq72hf@musicbox
Whole thread Raw
In response to COMMIT within function?  (Dawid Kuroczko <qnex42@gmail.com>)
Responses Re: COMMIT within function?
List pgsql-general
> Suppose I have vacuum_values() function, which removes all
> "no longer referenced" by parent column.  Kind of function
> to be run from time to time to clean table from crud.
> It looks like this:

    I suppose you have a good reason to not use a foreign key with "ON DELETE
CASCADE" ?

>                 FOR r IN SELECT value_id FROM values NATURAL LEFT JOIN
> other_tab WHERE other_tab.value_id IS NULL FOR UPDATE OF values LOOP
>                         DELETE FROM values WHERE value_id = r.value_id;
>                 END LOOP;
>                 RETURN;

    I don't remember the exact syntax (look in the DELETE docs) but you can
certainly put a left join inside a delete and do it all at once with only
one query, and it'll be faster to boot.

pgsql-general by date:

Previous
From: "gnari"
Date:
Subject: Re: Join between databases or (???)
Next
From: Tom Lane
Date:
Subject: Re: Join between databases or (???)