parsing SQLERRM ?

From: <david(dot)sahagian(at)emc(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: parsing SQLERRM ?
Date: 2012-06-14 21:07:38
Message-ID: F3CBFBA88397EA498B22A05FFA9EC49D8BE0D4E0@MX22A.corp.emc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

-dvs-

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guillaume Lelarge 2012-06-14 21:43:44 Re: Is there a way to ask PostgreSQL for the name of the computer it's running on?
Previous Message John R Pierce 2012-06-14 20:01:02 Re: Empty arrays vs. NULLs, 9.1 & 8.3