Re: replacing mysql enum - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: replacing mysql enum
Date
Msg-id 20041211084434.F34106@megazone.bigpanda.com
Whole thread Raw
In response to Re: replacing mysql enum  (Rod Taylor <pg@rbt.ca>)
List pgsql-sql
On Sat, 11 Dec 2004, Rod Taylor wrote:

> On Sat, 2004-12-11 at 07:47 -0800, Stephan Szabo wrote:
> > On Sat, 11 Dec 2004, Ian Barwick wrote:
> >
> > > (Oddly enough, putting the NULL in the CHECK constraint seems
> > > to make the constraint worthless:
> > > test=> create table consttest (field varchar(2)  check (field in
> > > (null, 'a','b','c')));
> > > CREATE TABLE
> > > test=> insert into consttest values ('xx');
> > > INSERT 408080 1
> > > test=> SELECT * from consttest ;
> > >  field
> > > -------
> > >  xx
> > > (1 row)
> > >
> > > Not sure what logic is driving this).
> >
> > The way NULL is handled in IN (because it's effectively an equality
> > comparison). Unless I miss-remember the behavior, foo in (NULL, ...) can
> > never return false and constraints are satisified unless the search
> > condition returns false for some row.  I think this means you need the
> > more verbose (field is null or field in ('a','b','c'))
>
> Actually, he just needs check(field in ('a', 'b', 'c')).  NULL is
> accepted unless explicitly denied (NOT NULL constraint or an IS NOT NULL
> check).

Right.  For the same reason, even. Really need to stop answering
messages before I wake up. :)


pgsql-sql by date:

Previous
From: Rod Taylor
Date:
Subject: Re: replacing mysql enum
Next
From: Ian Barwick
Date:
Subject: Re: replacing mysql enum