Re: unique constraint - bug? - Mailing list pgsql-general

From Oliver Elphick
Subject Re: unique constraint - bug?
Date
Msg-id 200007200753.e6K7rUA16521@linda.lfix.co.uk
Whole thread Raw
In response to Re: unique constraint - bug?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: unique constraint - bug?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Tom Lane wrote:
  >Merrill Oveson <merrill@actarg.com> writes:
  >> It appears as though the null value inserted for column b causes an
  >> abrogation of the unique constaint.
  >
  >Two nulls are never considered equal, therefore the unique constraint
  >does not trigger.
  >
  >This is correct behavior according to SQL92 4.10.2:
  >
  >         A unique constraint is satisfied if and only if no two rows in
  >         a table have the same non-null values in the unique columns. In
  >                               ^^^^^^^^
  >         addition, if the unique constraint was defined with PRIMARY KEY,
  >         then it requires that none of the values in the specified column or
  >         columns be the null value.

I think you are not interpreting this right:

        A unique constraint is satisfied if and only if no two rows in
        a table have the same non-null values in the unique columns.

I think it means that nulls are to be left out of account in the
comparison.  So

   a, NULL, c
   a, NULL, c

are neither equal nor unequal (as you say) but they do violate a UNIQUE
constraint because the nulls should be ignored altogether.  The two
rows do have the "same non-null values".

Surely this interpretation is closer to what users would expect?

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "Behold, what manner of love the Father hath bestowed
      upon us, that we should be called the sons of God..."
                                I John 3:1



pgsql-general by date:

Previous
From: "anuj"
Date:
Subject: Return PGresult
Next
From: Karel Zak
Date:
Subject: Re: [HACKERS] 8Ko limitation