PostgreSQL UNIQUE index not unique?

I have a table with a UNIQUE index with 12 columns. \d salesshows sales_uq UNIQUE, btree (a1, a2, a3, ... a12).

I execute the following query:

SELECT a1, a2, a3, ... a12 FROM sales GROUP BY a1, a2, a3, ... a12 HAVING count(1) > 1;

and I get a bunch of results. How is this possible ?! Is it possible that the index is there, but somehow disabled? Or may there be a problem with NULL? Or with floating point numbers (two columns in the index are of type double precision)?

+5
source share
2 answers

because two NULLs are not compared as equal, they play fun games with UNIQUE restrictions.

See the last paragraph of UNIQUE restrictions in the PostgreSQL Documentation :

, , , . . , , , .

+11

, . , .

+2

All Articles