pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PL/PGSQL question on transactions
3+ messages / 3 participants
[nested] [flat]

* PL/PGSQL question on transactions
@ 2002-04-12 15:50 Dan Schwitalla <acadrace@hotmail.com>
  2002-04-12 15:58 ` Re: PL/PGSQL question on transactions Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 1 reply; 3+ messages in thread

From: Dan Schwitalla @ 2002-04-12 15:50 UTC (permalink / raw)
  To: pgsql-sql

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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: PL/PGSQL question on transactions
  2002-04-12 15:50 PL/PGSQL question on transactions Dan Schwitalla <acadrace@hotmail.com>
@ 2002-04-12 15:58 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  0 siblings, 0 replies; 3+ messages in thread

From: Christopher Kings-Lynne @ 2002-04-12 15:58 UTC (permalink / raw)
  To: Dan Schwitalla <acadrace@hotmail.com>; +Cc: pgsql-sql

No - a function implicity runs in a transaction anyway.

Chris

On Fri, 12 Apr 2002, Dan Schwitalla wrote:

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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: PL/PGSQL question on transactions
@ 2002-04-12 16:34 Jie Liang <jie@stbernard.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Jie Liang @ 2002-04-12 16:34 UTC (permalink / raw)
  To: Dan Schwitalla <acadrace@hotmail.com>; pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2002-04-12 16:34 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-04-12 15:50 PL/PGSQL question on transactions Dan Schwitalla <acadrace@hotmail.com>
2002-04-12 15:58 ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2002-04-12 16:34 Re: PL/PGSQL question on transactions Jie Liang <jie@stbernard.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox