Rafa Couto wrote:
> I have got a plpgsql function:
> -- BEGIN;
>
> SELECT min(id) INTO _contacto_id FROM contactos
> WHERE contactos.operadora_id IS NULL AND contactos.actividad_id
> = _actividad_id;
>
> UPDATE contactos SET operadora_id = _operadora_id WHERE id = _contacto_id;
>
> -- COMMIT;
> and it works right, but I need atomic execution from --BEGIN and
> --COMMIT, and manual says it is not possible to have transactions in
> PL/pgSQL procedures :-(
OK - the WHOLE FUNCTION takes place within one transaction. So, in that
sense all changes are atomic.
However, if you want to prevent any changes to "contactos" in-between
those two statements you'll want additional locks. Read the chapter on
"concurrency control" for details. You might well want SELECT FOR UPDATE (and also just ORDER BY id LIMIT 1 rather
thanusing min(id)).
-- Richard Huxton Archonet Ltd