From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Alex Ignatov <a(dot)ignatov(at)postgrespro(dot)ru> |
Cc: | "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: User defined exceptions |
Date: | 2015-07-15 14:22:14 |
Message-ID: | CAKFQuwYsLNR60ANkPS3CurKH97HZJ+AR97Y3Rz_LFeS4OwjRGA@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Wed, Jul 15, 2015 at 10:10 AM, Alex Ignatov <a(dot)ignatov(at)postgrespro(dot)ru>
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?
>
I'm doubtful that it can be done presently.
If it were possible your exception_aaa function would have to be declared
IMMUTABLE. It also seems pointless to declare it security definer.
There is nothing in the documentation that suggests that (or, to be fair,
prohibits) the "condition" can be anything other than a pre-defined name or
a constant string. When plpgsql get a function body it doesn't go looking
for random functions to execute.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Pavel Stehule | 2015-07-15 15:54:48 | Re: User defined exceptions |
Previous Message | Alex Ignatov | 2015-07-15 14:10:18 | User defined exceptions |