Search Postgresql Archives

Re: parsing SQLERRM ?

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

 



david.sahagian@xxxxxxx wrote:
> (version == 9.1)
> 
> In my PL/pgSQL stored functions,
> I want to be able to distinguish which FK-constraint caused the
[foreign_key_violation] exception.
>   . . .
>   BEGIN
>     delete from MY_COOL_TABLE where id = 123 ;
>   EXCEPTION
>     WHEN foreign_key_violation THEN
>       CASE
>         WHEN (SQLERRM tells me it blew up because of FK X)  THEN . . .
;
>         WHEN (SQLERRM tells me it blew up because of FK Y)  THEN . . .
;
>         WHEN (SQLERRM tells me it blew up because of FK Z)  THEN . . .
;
>       END;
>     WHEN others THEN
>       raise;
>   END;
>   . . .
> 
> Is a "robust enough" parsing of SQLERRM actually the best/only way to
determine this ?

I think so.

Not that it is particularly nice, though.  It should be fairly robust to
search for the name of the constraint in the error message.

Yours,
Laurenz Albe

-- 
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