Re: unique constraint - bug?

From: "Oliver Elphick" <olly(at)lfix(dot)co(dot)uk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: unique constraint - bug?
Date: 2000-07-20 07:53:30
Message-ID: 200007200753.e6K7rUA16521@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
>Merrill Oveson <merrill(at)actarg(dot)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(dot)Elphick(at)lfix(dot)co(dot)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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Karel Zak 2000-07-20 08:00:17 Re: [HACKERS] 8Ko limitation
Previous Message Xavier ZIMMERMANN 2000-07-20 07:42:25 8Ko limitation