Re: Catch exceptions outside function - Mailing list pgsql-admin

From Albe Laurenz
Subject Re: Catch exceptions outside function
Date
Msg-id A737B7A37273E048B164557ADEF4A58B17C22011@ntex2010a.host.magwien.gv.at
Whole thread Raw
In response to Re: Catch exceptions outside function  (Roberto Grandi <roberto.grandi@trovaprezzi.it>)
List 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

pgsql-admin by date:

Previous
From: Roberto Grandi
Date:
Subject: Re: Catch exceptions outside function
Next
From: David Johnston
Date:
Subject: Re: Catch exceptions outside function