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 6096F3A630A for ; Sat, 11 Dec 2004 17:06:12 +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 83734-01 for ; Sat, 11 Dec 2004 17:06:10 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.207]) by svr1.postgresql.org (Postfix) with ESMTP id AF64F3A1D4C for ; Sat, 11 Dec 2004 17:06:09 +0000 (GMT) Received: by wproxy.gmail.com with SMTP id 71so895192wra for ; Sat, 11 Dec 2004 09:06:08 -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=W/N0/RwOAbHIXbuu37u84eMvWKPoM1gJHZmkUK6iJ+Go4j9Y8V1zJ2gaQ/5KG6QheHB57YUpcH309iCaYi3TWZeJNLLbnYW/ImOoTuiGLNXYZeSWTVHFUNwnqp3nNe+ujJbpljzFxie/HcbRprxF6LXrP/qiSba3lFmG9SuTH9E= Received: by 10.54.31.27 with SMTP id e27mr1591460wre; Sat, 11 Dec 2004 09:06:08 -0800 (PST) Received: by 10.54.5.50 with HTTP; Sat, 11 Dec 2004 09:06:08 -0800 (PST) Message-ID: <1d581afe041211090628da57e@mail.gmail.com> Date: Sat, 11 Dec 2004 18:06:08 +0100 From: Ian Barwick Reply-To: Ian Barwick To: Stephan Szabo Subject: Re: replacing mysql enum Cc: Kenneth Gonsalves , pgsql-sql@postgresql.org In-Reply-To: <20041211074227.J30051@megazone.bigpanda.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <04121110305520.21547@thenilgiris.com> <1d581afe04121104255557ea@mail.gmail.com> <20041211074227.J30051@megazone.bigpanda.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/63 X-Sequence-Number: 19683 On Sat, 11 Dec 2004 07:47:51 -0800 (PST), 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')) This works as expected, although for constraints the nullness of the column is better off handled by applying NOT NULL if necessary. 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 realising it has no effect. Ian Barwick