Re: 2 x duplicate key value violation: which exception comes first ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Marc Mamin" <M(dot)Mamin(at)intershop(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: 2 x duplicate key value violation: which exception comes first ?
Date: 2012-03-01 21:47:43
Message-ID: 18308.1330638463@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Marc Mamin" <M(dot)Mamin(at)intershop(dot)de> writes:
> I've a table with 1 primary key and 1 unique index.

> I would like to handle differently the duplicate key violations
> depending on which constraints are affected.
> (Within a plpgsql CATCH block, using SQLERRM).

> It seems, that when both constraints would be violated, the exception is
> always about the primary key.

> Can I rely on that or should I expect the exception order being random ?

Offhand I think the indexes will be inserted into in OID order, which
would typically be creation order, except after a wraparound. If you
rely on this you can expect your code to break sooner or later.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-03-01 21:50:29 Re: "Compressed data is corrupt"
Previous Message Scott Marlowe 2012-03-01 21:14:56 Re: 100% cpu usage on some postmaster processes kill the complete database