Re: My function run successfully with cursor, but can't change table

From: Kevin Grittner <kgrittn(at)ymail(dot)com>
To: 高健 <luckyjackgao(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: My function run successfully with cursor, but can't change table
Date: 2013-06-10 13:19:38
Message-ID: 1370870378.20393.YahooMailNeo@web162904.mail.bf1.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

高健 <luckyjackgao(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2013-06-10 13:21:26 Re: Postgresql - Currval Vs Session Pool
Previous Message Enrico Pirozzi 2013-06-10 12:41:34 Re: Question on explain