On Sat, 11 Dec 2004 10:30:55 +0530, Kenneth Gonsalves
<lawgon@thenilgiris.com> 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 not will pg
> permit you to enter a null value in the field?
No, and yes:
create table consttest (field varchar(2) check (field in ('a','b','c')));
insert into consttest values (null);
Note this does not emulate the MySQL ENUM datatype precisely,
because it's possible to reference the ENUM fields by index value
too.
(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).
Ian Barwick