Search Postgresql Archives

Re: Question about catching exception

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello

you have to parse a sqlerrm variable

CREATE OR REPLACE FUNCTION public.test(a integer, b integer)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
begin
  insert into foo values(a,b);
  exception when  unique_violation then
    raise notice '% %', sqlerrm, sqlstate;
end;
$function$

postgres=# select test(4,2);
NOTICE:  duplicate key value violates unique constraint "foo_b_key" 23505
 test
ââââââ

(1 row)

Time: 9.801 ms
postgres=# select test(3,2);
NOTICE:  duplicate key value violates unique constraint "foo_a_key" 23505
 test
ââââââ

(1 row)

Time: 17.167 ms

regards

Pavel Stehule



> If the "do stuff" part can result in two different unique_violation
> exception (having two unique constraints), how can I detect which one
> was triggered?
>
> --
> Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux