[DB-SIG] Portable method of determining which column wasn't unique?
Chris Cogdon
chris@cogdon.org
Thu, 10 Oct 2002 13:21:38 -0700
On Thursday, Oct 10, 2002, at 13:08 US/Pacific, Dustin Sallings wrote:
> Around 15:57 on Oct 10, 2002, Johannes Erdfelt said:
>
> The correct way to do it is to have a unique index that spans
> those two columns. If your insert fails, the name's taken.
There ARE circumstances where you have two columns that are
independent, but need to be unique.
For example, imagine a table of Artists. Amongst other information, one
column represents the login name used by the artist to identify himself
(or herself) to the system. Another column is the 'gallery name' used
to present the artist to the outside world. Both columns need to be
unique, as you cannot have two login names, nor two gallery names, that
are the same. But the two are definitely independent.
Postgresql, for example, will tell you the column name that is causing
the problem as the value to the exception. Its embedded in a bunch of
text, so you may have to do some text parsing to get the error message
out.
Other DBMSs ... .who knows? :) So... the answer is... it's not
portable, but should be easily containable.
--
("`-/")_.-'"``-._ Chris Cogdon <chris@cogdon.org>
. . `; -._ )-;-,_`)
(v_,)' _ )`-.\ ``-'
_.- _..-_/ / ((.'
((,.-' ((,/ fL