Transaction in plpgslq

From: Rafa Couto <rafacouto(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Transaction in plpgslq
Date: 2005-05-20 10:47:31
Message-ID: 22df564b05052003479481da1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have got a plpgsql function:

CREATE FUNCTION nueva_llamada(integer, integer) RETURNS integer

as

DECLARE
_operadora_id ALIAS FOR $1;
_actividad_id ALIAS FOR $2;
_contacto_id integer;

BEGIN

-- 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;

INSERT INTO llamadas (contacto_id, operadora_id, fecha)
VALUES (_contacto_id, _operadora_id, now());

RETURN _contacto_id;
END

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 :-(

May be with LOCK TABLE?

--
Rafa Couto (caligari)
mailto:rafacouto(at)gmail(dot)com
urgentes (sólo texto): rafa112(at)amena(dot)com
PGP 0x30EC5C31 [E6BF 11EF FE55 38B1 CF7E 9380 58E5 9FA3]

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Wei Weng 2005-05-20 17:22:42 How do I quit in the middle of a SQL script?
Previous Message Mark Fenbers 2005-05-20 10:25:41 Re: Aggregate Functions Template