Re: Unique constraint over null values - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Unique constraint over null values
Date
Msg-id 200209301050.05473.josh@agliodbs.com
Whole thread Raw
In response to Re: Unique constraint over null values  (Thrasher <thrasher@fibers.upc.es>)
List pgsql-sql
Thrasher,

> I think I'll follow your advice, as this is the method that I had in my
> pocket to use if I had no response. I tried with TRIM and other
> functions in the CHECK constraint, but I guess that I cannot use
> functions over a check field.
>
> It surprised me, but anyway, I'll do that.
>
> Thanks a lot for your prompt reply

No problem.  You should also add a second constraint:
CHECK ((type = 'x' AND data2 <> 'blank value') OR (type = 'y' AND data2 =
'blank value'))

To enforce your other criterion.

Keeop in mind that depending on the rest of your data structure, there are
probably 8 different ways to approach this problem.  I'd reccomend, in fact,
a quick reading of Pascal's "Practical Issues in Database Management" on
normalization to see the different table structures that might work for you.

--
-Josh BerkusAglio Database SolutionsSan Francisco



pgsql-sql by date:

Previous
From: Thrasher
Date:
Subject: Re: Unique constraint over null values
Next
From: Tom Lane
Date:
Subject: Re: [GENERAL] CURRENT_TIMESTAMP