agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Alex Ignatov <a.ignatov@postgrespro.ru>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: User defined exceptions
Date: Fri, 17 Jul 2015 18:31:39 +0300
Message-ID: <55A91FDB.1010706@postgrespro.ru> (raw)
In-Reply-To: <55A8AFF3.7040305@ocslab.com>
References: <55A669CA.3070302@postgrespro.ru>
<55A8AFF3.7040305@ocslab.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
On 17.07.2015 10:34, Alexey Bashtanov wrote:
> On 15.07.2015 17:10, Alex Ignatov wrote:
>> Hello all!
>> Trying to emulate "named" user defined exception with:
>> CREATE OR REPLACE FUNCTION exception_aaa () RETURNS text AS $body$
>> BEGIN
>> return 31234;
>> END;
>> $body$
>> LANGUAGE PLPGSQL
>> SECURITY DEFINER
>> ;
>>
>> do $$
>> begin
>> raise exception using errcode=exception_aaa();
>> exception
>> when sqlstate exception_aaa()
>> then
>> raise notice 'got exception %',sqlstate;
>> end;
>> $$
>>
>> Got:
>>
>> ERROR: syntax error at or near "exception_aaa"
>> LINE 20: sqlstate exception_aaa()
>>
>> I looks like "when sqlstate exception_aaa()" doesn't work.
>>
>> How can I catch exception in this case?
>
> Hello Alex,
>
> The following workaround could be used:
>
> do $$
> begin
> raise exception using errcode = exception_aaa();
> exception
> when others then
> if sqlstate = exception_aaa() then
> raise notice 'got exception %',sqlstate;
> else
> raise; --reraise
> end if;
> end;
> $$
>
> Not sure if its performance is the same as in simple exception catch,
> maybe it would degrade.
>
> Best Regards,
> Alexey Bashtanov
Yep already used this trick =)
Anyway thank you!
--
Alex Ignatov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
view thread (6+ messages)
Message-ID: <55A91FDB.1010706@postgrespro.ru>
Permalink: ../55A91FDB.1010706@postgrespro.ru/
Also on: postgresql.org/message-id/55A91FDB.1010706@postgrespro.ru
reply
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-sql@postgresql.org
Cc: a.ignatov@postgrespro.ru
Subject: Re: User defined exceptions
In-Reply-To: <55A91FDB.1010706@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox