Re: Unique constraint over null values

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Thrasher <thrasher(at)fibers(dot)upc(dot)es>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Unique constraint over null values
Date: 2002-09-30 17:50:05
Message-ID: 200209301050.05473.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Berkus
Aglio Database Solutions
San Francisco

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2002-09-30 17:59:00 Re: [SQL] CURRENT_TIMESTAMP
Previous Message Thrasher 2002-09-30 17:41:58 Re: Unique constraint over null values