X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0AB803A6107 for ; Sat, 11 Dec 2004 12:26:07 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22093-02 for ; Sat, 11 Dec 2004 12:25:54 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.199]) by svr1.postgresql.org (Postfix) with ESMTP id D94CC3A5E48 for ; Sat, 11 Dec 2004 12:25:54 +0000 (GMT) Received: by wproxy.gmail.com with SMTP id 70so674072wra for ; Sat, 11 Dec 2004 04:25:37 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=CiLYlb79otkNEVZnGn5Y8uL3ecSKlAVPbPJ8lgqcOFMS67t5xdsFtgIDfSvPF8htwaeTQU8FPlVOC3Hyqz6B5h93/AFCi1OU/cbdtb1jVk4svoh5JZuzMK0sv4fZ+VNahjDZhHyR6bRTtztifVNqOv3wCnnNk8l7vUfMO1uZKdE= Received: by 10.54.15.60 with SMTP id 60mr775755wro; Sat, 11 Dec 2004 04:25:37 -0800 (PST) Received: by 10.54.5.50 with HTTP; Sat, 11 Dec 2004 04:25:37 -0800 (PST) Message-ID: <1d581afe04121104255557ea@mail.gmail.com> Date: Sat, 11 Dec 2004 13:25:37 +0100 From: Ian Barwick Reply-To: Ian Barwick To: Kenneth Gonsalves Subject: Re: replacing mysql enum Cc: pgsql-sql@postgresql.org In-Reply-To: <04121110305520.21547@thenilgiris.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <04121110305520.21547@thenilgiris.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.024 tagged_above=0 required=5 tests=RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200412/58 X-Sequence-Number: 19678 On Sat, 11 Dec 2004 10:30:55 +0530, Kenneth Gonsalves 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