Re: unique key and nulls - Mailing list pgsql-hackers

From Tom Lane
Subject Re: unique key and nulls
Date
Msg-id 9031.1165343417@sss.pgh.pa.us
Whole thread Raw
In response to unique key and nulls  (Patrick Welche <prlw1@newn.cam.ac.uk>)
List 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


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Preserving Cluster-Wise Data
Next
From: Volkan YAZICI
Date:
Subject: Re: Preserving Cluster-Wise Data