Re: when to use NULL and when to NOT NULL DEFAULT ''

From: David Garamond <lists(at)zara(dot)6(dot)isreserved(dot)com>
To: Michael Glaesemann <grzm(at)myrealbox(dot)com>
Cc: Miles Keaton <mileskeaton(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: when to use NULL and when to NOT NULL DEFAULT ''
Date: 2004-10-08 13:19:26
Message-ID: 416693DE.20707@zara.6.isreserved.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Michael Glaesemann wrote:
> For employees you don't have birthdates for, you could use NULL in SQL.
> However, as relationally one shouldn't use NULL, you would do the
> following:
>
> CREATE TABLE employees (
> emp_id SERIAL NOT NULL UNIQUE
> , emp_name TEXT NOT NULL
> );
>
> CREATE TABLE employees_birthdates (
> emp_id INTEGER NOT NULL REFERENCES employees (emp_id)
> , birthdate DATE NOT NULL
> );
>
> In any case, one would never use NULL. Either the domain includes a
> value for all possible values (including N/A) or you set up the db
> schema appropriately.

Hm, that can be painful. What if I have ten optional attributes;
separate them to ten different tables?

--
dave

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2004-10-08 13:27:14 Re: interesting! a sequence clashes with data already in that table
Previous Message David Garamond 2004-10-08 13:16:45 Re: text + text