Re: [subxacts] Aborting a function - Mailing list pgsql-hackers

From Rod Taylor
Subject Re: [subxacts] Aborting a function
Date
Msg-id 1089319923.5999.253.camel@jester
Whole thread Raw
In response to [subxacts] Aborting a function  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
Responses Re: [subxacts] Aborting a function
List pgsql-hackers
> create function crashme2() returns int strict language plpgsql as '
> begin
>    subbegin;
>       select foo;         -- aborts the transaction
>                           -- did not close the subxact
> end;';

I'm not sure I follow. Are you saying that the following code or
something similar will never work?

create function insertOrUpdateTabX(int, text) returns as '
BEGIN SUBBEGIN;   INSERT INTO tab (key, col) VALUES ($1, $2);
 GET DIAGNOSTICS status = SQLSTATE; IF (status != 000000) THEN   -- Got an error, determine what it is   SUBABORT;
   IF (status = 23505) THEN     -- This entry already exists. Update the value instead     UPDATE tab SET col = $2
WHEREkey = $1;   ELSE     RAISE EXCEPTION ''Unrecoverable error'';   END IF ELSE   SUBCOMMIT: END IF;
 

END;
' language plpgsql;




pgsql-hackers by date:

Previous
From: "Dave Page"
Date:
Subject: Re: Initdb error
Next
From: Alvaro Herrera
Date:
Subject: Re: [subxacts] Aborting a function