Received: from MAIL01.stbernard.com (mail01.stbernard.com [64.154.93.162]) by postgresql.org (Postfix) with ESMTP id D72F1474E71 for ; Fri, 12 Apr 2002 12:34:28 -0400 (EDT) Received: by MAIL01.stbernard.com with Internet Mail Service (5.5.2653.19) id ; Fri, 12 Apr 2002 09:34:34 -0700 Message-ID: <7C760DAA511DC74B99E7D22189F786F1906E00@MAIL01.stbernard.com> From: Jie Liang To: 'Dan Schwitalla' , pgsql-sql@postgresql.org Subject: Re: PL/PGSQL question on transactions Date: Fri, 12 Apr 2002 09:34:29 -0700 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" X-Archive-Number: 200204/152 X-Sequence-Number: 7417 Nope. As my understanding, in a PL/pgSQL function, all statements are in ONE transaction, you do not need another pair of begin/end. If transaction failed, it abort whole thing anyway. Jie Liang -----Original Message----- From: Dan Schwitalla [mailto:acadrace@hotmail.com] Sent: Friday, April 12, 2002 8:50 AM To: pgsql-sql@postgresql.org Subject: [SQL] PL/PGSQL question on transactions Can you imbed BEGIN; and COMMIT; statements in the body of a pl/pgsql function? I am getting a parse error upon execution when I try it. Code: CREATE FUNCTION chitadj(integer,integer) RETURNS integer AS ' DECLARE result integer; oldamount integer; BEGIN BEGIN; SELECT INTO oldamount chits FROM avatar WHERE avatar_id = $1; IF oldamount IS NULL THEN RETURN -1; END IF; IF ((oldamount < abs($2)) AND ($2 < 0)) THEN RETURN -2; END IF; result := oldamount + $2; RETURN result; COMMIT; END; ' language 'plpgsql'; ------------------------- Dan _________________________________________________________________ Join the world's largest e-mail service with MSN Hotmail. http://www.hotmail.com ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org