Re: COMMIT within function?
| От | Pierre-Frédéric Caillaud |
|---|---|
| Тема | Re: COMMIT within function? |
| Дата | |
| Msg-id | opsht78502cq72hf@musicbox обсуждение исходный текст |
| Ответ на | COMMIT within function? (Dawid Kuroczko <qnex42@gmail.com>) |
| Ответы |
Re: COMMIT within function?
|
| Список | 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 по дате отправления: