Re: SQL design question: null vs. boolean values - Mailing list pgsql-sql

From PFC
Subject Re: SQL design question: null vs. boolean values
Date
Msg-id opskpk5jr6th1vuj@musicbox
Whole thread Raw
In response to Re: SQL design question: null vs. boolean values  ("j.random.programmer" <javadesigner@yahoo.com>)
List pgsql-sql

> create table xyz
> (
> field_foo   char(1) check (field_foo in 'y', 'n'),
> foo_detail varchar(255),
> check (
>   case
>     when field_foo='y' and foo_detail is null
>         then false
>     else true
>   end
>   )
> );
A simpler check would be :
CHECK(    (field_foo = 'y' AND foo_detail IS NOT NULL)OR    ( (field_foo = 'n' OR field_foo IS NULL) AND foo_detail IS
NULL))
Which means " field_foo can be y, n, or NULL, and foo_detail should be  
null except if field_foo is 'y' "

Also, IMHO, the Y/N/unknown case should have three values, NULL meaning  
'the user has not answered this question'. Because if you insert a blank  
row in the table and fill it afterwards, you'll know if it was 'answered  
unknown' or 'unanswered'.


pgsql-sql by date:

Previous
From: "j.random.programmer"
Date:
Subject: Re: SQL design question: null vs. boolean values
Next
From: Theo Galanakis
Date:
Subject: Re: pgmirror