Re: My function run successfully with cursor, but can't change table - Mailing list pgsql-general

From Kevin Grittner
Subject Re: My function run successfully with cursor, but can't change table
Date
Msg-id 1370870378.20393.YahooMailNeo@web162904.mail.bf1.yahoo.com
Whole thread Raw
In response to My function run successfully with cursor, but can't change table  (高健 <luckyjackgao@gmail.com>)
Responses Re: My function run successfully with cursor, but can't change table
Re: My function run successfully with cursor, but can't change table
List pgsql-general
高健 <luckyjackgao@gmail.com> wrote:

> CREATE OR REPLACE Function ...

> BEGIN
>   BEGIN

>     UPDATE ...
>     COMMIT;

>   EXCEPTION
>   WHEN OTHERS THEN
>   END;
> END;

> But when I select the table again, I found it not changed.

> Anybody know the reason, maybe there are some wrong way by
> which I use the cursor.

It has nothing to do with the way you are using the cursor; your
problem is that you are causing an error by attempting to COMMIT
inside a function (which is not allowed).  This rolls back the
subtransaction defined by the BEGIN/EXCEPTION block.  You then
suppress any display of the error with the WHEN OTHERS block.

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


pgsql-general by date:

Previous
From: Enrico Pirozzi
Date:
Subject: Re: Question on explain
Next
From: Albe Laurenz
Date:
Subject: Re: Postgresql - Currval Vs Session Pool