Re: COMMIT within function?

From: Pierre-Frédéric Caillaud <lists(at)boutiquenumerique(dot)com>
To: "Dawid Kuroczko" <qnex42(at)gmail(dot)com>, "Pgsql General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: COMMIT within function?
Date: 2004-11-21 23:16:07
Message-ID: opsht78502cq72hf@musicbox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-11-21 23:18:13 Re: Join between databases or (???)
Previous Message gnari 2004-11-21 23:14:03 Re: Join between databases or (???)