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