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 4D4D63A2C8C for ; Sat, 15 Jan 2005 15:09:15 +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 17025-06 for ; Sat, 15 Jan 2005 15:09:09 +0000 (GMT) Received: from anchor-post-31.mail.demon.net (anchor-post-31.mail.demon.net [194.217.242.89]) by svr1.postgresql.org (Postfix) with ESMTP id 857D63A2C8A for ; Sat, 15 Jan 2005 15:09:12 +0000 (GMT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-31.mail.demon.net with esmtp (Exim 4.42) id 1CppXD-000BDq-4L; Sat, 15 Jan 2005 15:08:15 +0000 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 2BA6D163C1; Sat, 15 Jan 2005 15:09:11 +0000 (GMT) Message-ID: <41E93217.5020900@archonet.com> Date: Sat, 15 Jan 2005 15:09:11 +0000 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "j.random.programmer" Cc: pgsql-sql@postgresql.org Subject: Re: SQL design question: null vs. boolean values References: <20050115144018.8932.qmail@web14207.mail.yahoo.com> In-Reply-To: <20050115144018.8932.qmail@web14207.mail.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.075 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200501/113 X-Sequence-Number: 19901 j.random.programmer wrote: > Hi all: > > I was wondering if anyone had recommendations for the > following scenarios: > > (A) > I have three radio boxes in the user form > > field_foo > []yes > []no > []unknown > > These are mutually exclusive and user input is always > required. > > So in the database, should I have something like: > > field_foo char(1) not null check (field_foo in 'y', > 'n', 'u') > ....OR.... > field_foo char(1) check (field_foo in 'y', 'n') > > The second choice always implies that NULL means > unknown, > whereas for the first choice, unknown is coded as 'u'. Option 1 - the value is known, the user made a choice and it was to click the "unknown" box. The box could be labelled "marmalade" just as easily. > (B) > In the user form, I have a field like: > > field_bar > [] select_me > > with ONE choice, which is optional. > > Should I code this as: > > field_bar char(1) not null check (field_foo in 'y', > 'n') > ....OR.... > field_foo char(1) check (field_foo in 'y') > > The second choice always implies that NULL means not > selected whereas whereas for the first choice, > selected is coded > as 'y' and not selected coded as 'n' > > Any advice, dear SQL experts ? First option. I'm not convinced the choice is optional - you've presented the tickbox to them so you have to assume they've read it and chosen not to tick it. -- Richard Huxton Archonet Ltd