pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thrasher <thrasher@fibers.upc.es>
To: pgsql-sql@postgresql.org
Subject: Re: Unique constraint over null values
Date: Mon, 30 Sep 2002 19:41:58 +0200
Message-ID: <3D988CE6.5070505@fibers.upc.es> (raw)
References: <3D98884F.9070704@fibers.upc.es>
	<200209301033.22795.josh@agliodbs.com>

Hi Josh,

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

Thrasher


Josh Berkus wrote:
> Thrasher,
> 
> 
>>where type can be 's' for 'single' and 'x' for extended, so s should 
>>mean that there is only the type and data1 field, and x means that all 
>>fields are set.
>>
>>How can I set a unique constraint like CHECK (type = 's' AND UNIQUE 
>>(type, data1)) OR (type = 'x' AND UNIQUE (type, data1, data2)) ?
>>
>>The documentation says that 2 NULL values are different, so no unique 
>>constraint can be set over it.
> 
> 
> Simple.  Don't use NULLs.   NULL means "unknown".   You should use a 
> differnent value, such as a blank string or "N/A" or "000000000000000" to 
> represent "intentionally left blank".
> 
> Then you can set data2 NOT NULL and use a regular UNIQUE constraint.
> 
> BTW, you have defined your data columns as CHAR, not VARCHAR.  You do know 
> that this implies that your data columns will be *exactly* 16 characters in 
> length?
> 




view thread (4+ messages)  latest in thread

Message-ID: <3D988CE6.5070505@fibers.upc.es>
Permalink:  ../3D988CE6.5070505@fibers.upc.es/
Also on:    postgresql.org/message-id/3D988CE6.5070505@fibers.upc.es

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: thrasher@fibers.upc.es
  Subject: Re: Unique constraint over null values
  In-Reply-To: <3D988CE6.5070505@fibers.upc.es>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox