Skip site navigation (1) Skip section navigation (2)

Re: pgsql: Add PL/pgSQL SQLSTATE and SQLERRM support

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>,Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz>,pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Add PL/pgSQL SQLSTATE and SQLERRM support
Date: 2005-05-26 04:00:24
Message-ID: 23183.1117080024@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-committerspgsql-patches
Neil Conway <neilc(at)samurai(dot)com> writes:
> Tom Lane wrote:
>> Alternatively we could make them local to any block that contains an
>> EXCEPTION clause, which would fix point 3 and also go a long way towards
>> addressing the unnecessary-overhead gripe.  However that would mean that
>> an attempt to reference them from outside an exception handler would
>> probably fail outright, rather than deliver either NULLs or
>> 00000/"Successful completion".

> This behavior sounds fine to me.

I think the key distinction between this proposal and my other one
(that SQLSTATE/SQLERRM be procedure-local) is whether you want the error
status to be available to code that immediately follows the BEGIN block
containing the exception handler.  That is, consider code like

	BEGIN
		-- do something perilous
	EXCEPTION
		WHEN OTHERS THEN -- nothing much
	END;
	IF SQLSTATE = '42000' THEN ...

At the moment I don't have a strong opinion about this.  It seems
closely analogous to the question whether a loop iteration variable
should remain defined after the loop exits --- you can find cases
where that's handy, but you can also argue it shouldn't be used.
plpgsql itself is schizophrenic on the point (see integer versus
record FOR-loops), which means we don't have a solid precedent to go by.

			regards, tom lane

In response to

Responses

pgsql-committers by date

Next:From: Bruce MomjianDate: 2005-05-26 04:08:32
Subject: pgsql: Back out SQLSTATE and SQLERRM support.
Previous:From: Bruce MomjianDate: 2005-05-26 03:48:25
Subject: pgsql: Display only 9 not 10 digits of precision for timestamp values

pgsql-patches by date

Next:From: Bruce MomjianDate: 2005-05-26 04:11:17
Subject: Re: [COMMITTERS] pgsql: Add PL/pgSQL SQLSTATE and SQLERRM support
Previous:From: Neil ConwayDate: 2005-05-26 03:37:55
Subject: Re: pgsql: Add PL/pgSQL SQLSTATE and SQLERRM support

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group