Re: plpgsql: how to get the exception's detail information?

From: Filip Rembiałkowski <plk(dot)zuber(at)gmail(dot)com>
To: Muiz <work(dot)muiz(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: plpgsql: how to get the exception's detail information?
Date: 2011-12-01 12:07:02
Message-ID: CAP_rwwmouN1HeDaVXSRvohK3haRRoPXg2yc5KuvqqJSwOXxxxw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

2011/11/29 Muiz <work(dot)muiz(at)gmail(dot)com>:
>    I write a function to execute a sql string. E.g. "update tableA set
> field1='abc' where name='123'; deletee from tableB where id=333;"
>    The following is my function:
> -----------------------------------------------------------------------------------------------------------------------------
> CREATE OR REPLACE FUNCTION no_err_rollback()
>   RETURNS boolean AS
> $BODY$
> BEGIN
>     ROLLBACK;
>     RETURN TRUE;
> EXCEPTION
>      WHEN others THEN
>             RETURN TRUE;
> END
> $BODY$
>   LANGUAGE plpgsql;
>

I think this does not do what you think.

Transaction control commands (like ROLLBACK) inside functions does not
work in PostgreSQL.
Using ROLBACK in PgSQL will raise an exception (which you forcibly
ignored above).
This is a big feature which is sometimes called "autonomous
transactions" and is not yet implemented, AFAIK.
You can test this quite easilly; use txid_current() function to check
current transaction ID.

>  1. when I execute a sql, can I get the total records user updated or
> deleted ?
see GET DIAGNOSTICS ->
http://www.postgresql.org/docs/9.0/static/plpgsql-statements.html
NOTE: this will count rows affected by last query only.

>  2. if I cache the exceptions, can I get the detail information?
what do you mean by "cache exceptions"?

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Abhinandan Raghavan 2011-12-06 13:57:19 Self-Join
Previous Message David Johnston 2011-12-01 01:12:22 Re: running totals with end of month line