From: David Johnston <polobo@yahoo.com>
To: pgsql-admin@postgresql.org
Subject: Re: Catch exceptions outside function
Date: Wed, 18 Sep 2013 06:23:33 -0700 (PDT)
Message-ID: <1379510613320-5771426.post@n5.nabble.com> (raw)
In-Reply-To: <515129598.391580.1379505217287.JavaMail.root@trovaprezzi.it>
References: <452256586.387717.1379499437400.JavaMail.root@trovaprezzi.it>
<A737B7A37273E048B164557ADEF4A58B17C21F41@ntex2010a.host.magwien.gv.at>
<515129598.391580.1379505217287.JavaMail.root@trovaprezzi.it>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-admin>
Roberto Grandi wrote
> Hi
>
> 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?
Set your timeout longer than 5 seconds or sleep less than one second.
You cannot catch an exception directly in the top-level SQL language portion
of a command environment. If an exception gets that far your transaction
has failed and you have to ROLLBACK.
You can use savepoints to limit how far you have to rollback - see the
documentation.
Exceptions should not occur (or do so rarely) and so they cannot be simply
ignored. If you have code that you expect to throw an exception you should
try to rewrite it to test first and return true/false for availability. not
always possible so catch and savepoints are ther to do if you must.
David J.
P.S. version 8.3 is no loner supported.
P.P.S please follow list convention and bottom or interleave post.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Catch-exceptions-outside-function-tp5771398p5771426.html
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: polobo@yahoo.com
Subject: Re: Catch exceptions outside function
In-Reply-To: <1379510613320-5771426.post@n5.nabble.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox