Re: disallowing multiple NULLs in a unique constraint

From: David Garamond <lists(at)zara(dot)6(dot)isreserved(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: disallowing multiple NULLs in a unique constraint
Date: 2004-02-09 13:19:21
Message-ID: 402788D9.8000607@zara.6.isreserved.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
>>SQL Server only allow one NULL in a unique constraint column (it's the
>>unique index that does that, so the unique constraint behaves like that
>>too). The question is, what is the best way to simulate that behaviour
>>in Postgres?
>
> The best way is to rewrite your app to not depend on nonstandard
> semantics. SQL Server is unquestionably violating the SQL spec here,
> and it's not out of the question that Microsoft might realize that and
> fix it, leaving you up the creek on that platform as well as Postgres.
>
> Instead of using NULL in that fashion, perhaps you could choose a
> non-null dummy value to use instead.

Thanks, Tom. Yeah, that answer was expected :-) DB2 is also violating
specs here, though they have a syntax (UNIQUE WHERE NOT NULL or something).

Btw, one example case: a table containing a tree with adjacency list.
The root node is the one that doesn't have a parent (parent_id is NULL).
parent_id REFERENCES thetable(id). How do we restrict the table to have
only one root node?

--
dave

In response to

Browse pgsql-general by date

  From Date Subject
Next Message anorakgirl 2004-02-09 13:37:40 functions and temporary tables
Previous Message Rajan Bhide 2004-02-09 12:06:39 Performing COPY Command