Re: unique key and nulls
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Patrick Welche <prlw1@newn.cam.ac.uk>
Cc: pgsql-hackers@postgresql.org
Date: 2006-12-05T18:30:17Z
Lists: pgsql-hackers
Patrick Welche <prlw1@newn.cam.ac.uk> writes: > patrimoine=# alter table socket add unique(port_id); > NOTICE: ALTER TABLE / ADD UNIQUE will create implicit index "socket_port_id_key" for table "socket" > ERROR: could not create unique index > DETAIL: Table contains duplicated values. > patrimoine=# select port_id,count(id) from socket group by port_id having count(id)>2; count(id)>1 would be the appropriate check, no? Or really count(*)>1 ... the above will give misleading answers if id can be null. regards, tom lane