[SQL] replacing mysql enum

2004-12-10 Thread Kenneth Gonsalves
hi, from mysql: field enum('a','b','c') default null, i translated this as: field varchar(2) check (field in (null,'a','b','c')), is it necessary to put the 'null' in the check condition? if not will pg permit you to enter a null value in the field? regards kg ---(en

Re: [SQL] replacing mysql enum

2004-12-11 Thread Ian Barwick
On Sat, 11 Dec 2004 10:30:55 +0530, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote: > hi, > > from mysql: > > field enum('a','b','c') default null, > > i translated this as: > > field varchar(2) check (field in (null,'a','b','c')), > > is it necessary to put the 'null' in the check condition? if

Re: [SQL] replacing mysql enum

2004-12-11 Thread Stephan Szabo
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'); > INS

Re: [SQL] replacing mysql enum

2004-12-11 Thread Rod Taylor
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')))

Re: [SQL] replacing mysql enum

2004-12-11 Thread Stephan Szabo
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 v

Re: [SQL] replacing mysql enum

2004-12-11 Thread Ian Barwick
On Sat, 11 Dec 2004 07:47:51 -0800 (PST), Stephan Szabo <[EMAIL PROTECTED]> 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 i

Re: [SQL] replacing mysql enum

2004-12-11 Thread Greg Stark
Ian Barwick <[EMAIL PROTECTED]> writes: > What I still don't quite understand is why IN in a CHECK context is > handled differently to say: select 1 where 'x' in (null,'a','b','c') ? > This could be a bit of a gotcha for anyone constructing a constraint > similar to the original poster's and not

Re: [SQL] replacing mysql enum

2004-12-11 Thread Josh Berkus
Kenneth, > i translated this as: > > field varchar(2) check (field in (null,'a','b','c')), While this isn't the question you asked, might I encourage you to use DOMAINs instead? I.e.: CREATE DOMAIN abc_col AS TEXT CHECK VALUE IN ( 'a', 'b', 'c' ); Then you declare the table as: tabl

Re: [SQL] replacing mysql enum

2004-12-11 Thread Tom Lane
Ian Barwick <[EMAIL PROTECTED]> writes: > (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'); > INSE