Search Postgresql Archives

Re: unique constraint with a null column?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



CSN <cool_screen_name90001@xxxxxxxxx> writes:
> I have three columns, and one of them can be null. I'd
> like to create a unique constraint across all three
> columns and allow only one null value. e.g.

UNIQUE won't do that for you, but you could brute force it with a
unique constraint plus a check constraint along the lines of
	(a notnull AND b notnull) OR
	(a notnull AND c notnull) OR
	(b notnull AND c notnull)

However, the real question is whether you think that "unique"
means "no more than one instance of x,y,NULL".  If that's what
you mean then UNIQUE isn't going to enforce it ...

			regards, tom lane


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux