| From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
|---|---|
| To: | Alex Ignatov <a(dot)ignatov(at)postgrespro(dot)ru> |
| Cc: | postgres list <pgsql-sql(at)postgresql(dot)org> |
| Subject: | Re: User defined exceptions |
| Date: | 2015-07-15 15:54:48 |
| Message-ID: | CAFj8pRCeqR2m5fCtbAn6tUaZRoNb-w+bGeL7-A9qr72_GqBY_w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
2015-07-15 16:10 GMT+02:00 Alex Ignatov <a(dot)ignatov(at)postgrespro(dot)ru>:
> 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?
>
this syntax is working only for builtin exceptions. PostgreSQL has not
declared custom exceptions like SQL/PSM.
You have to use own sqlcode and catch specific code.
Regards
Pavel
> --
> Alex Ignatov
> Postgres Professional: http://www.postgrespro.com
> The Russian Postgres Company
>
>
>
>
> ------------------------------
> [image: Avast logo] <https://www.avast.com/antivirus>
>
> This email has been checked for viruses by Avast antivirus software.
> www.avast.com <https://www.avast.com/antivirus>
>
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alexey Bashtanov | 2015-07-17 07:34:11 | Re: User defined exceptions |
| Previous Message | David G. Johnston | 2015-07-15 14:22:14 | Re: User defined exceptions |