Re: Catch exceptions outside function

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "Roberto Grandi *EXTERN*" <roberto(dot)grandi(at)trovaprezzi(dot)it>
Cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Catch exceptions outside function
Date: 2013-09-18 12:57:50
Message-ID: A737B7A37273E048B164557ADEF4A58B17C22011@ntex2010a.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Roberto Grandi wrote:
> this is my script in details, remember that I launch it by .Net code (devart connector):
>
>
> SET LOCAL statement_timeout TO 1000;
> BEGIN;
>
> SELECT pg_sleep(5); -- QUERY that is long running;
>
> -- Some exception catch such as EXCEPTION
>
> END;
>
>
> I supposed my code can throw an eception for timeout and I would catch it. Otherwise consecutives
> queries report "Transaction is aborted message error".
>
> Do you have any suggestion for me?

I see.

You cannot catch an exception in SQL, as far as I know (unless you use a DO
statement, which was introduced in PostgreSQL 9.0).

You could use a "poor man's DO" by creating a function that does
what you want, catch the exception in PL/pgSQL, call the function and drop it.

But I really think that this should be handled on the application side,
i.e. your code should ignore the exception.

Yours,
Laurenz Albe

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message David Johnston 2013-09-18 13:23:33 Re: Catch exceptions outside function
Previous Message Roberto Grandi 2013-09-18 11:53:37 Re: Catch exceptions outside function