How to implement transaction in plpgsql?

From: "Corn" <corn(at)tryit(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: How to implement transaction in plpgsql?
Date: 2001-09-14 05:05:27
Message-ID: 9ns2vd$160u$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dear all,

How to implement transaction in plpgsql?
I have try to use it but fail. And I don't know the reason.
Here is my function...

CREATE FUNCTION sp_templatetouser(INTEGER, INTEGER) RETURNS INTEGER AS '
DECLARE
puserid ALIAS FOR $1;
pplateid ALIAS FOR $2;
rec_affected INTEGER;
BEGIN

BEGIN WORK;
DELETE FROM userrights WHERE userid = puserid;
INSERT INTO userrights SELECT puserid, rightid, allow FROM platedetails
WHERE plateid = pplateid;

GET DIAGNOSTICS rec_affected = ROW_COUNT;
IF rec_affected = 3 THEN
RETURN 1;
ELSE
ROLLBACK WORK;
RETURN 0;
END IF;
COMMIT WORK;
END;
' LANGUAGE 'plpgsql';

best regards,
Corn.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2001-09-14 06:38:00 Re: count of occurences PLUS optimisation
Previous Message Justin Clift 2001-09-14 04:54:24 Re: business perspective