Re: NULL values - Mailing list pgsql-general

From Chad R. Larson
Subject Re: NULL values
Date
Msg-id 20010710155013.B1547@ecibsd1.ecinet.com
Whole thread Raw
In response to NULL values  ("Mark Muffett" <mark@muffett.net>)
List pgsql-general
On Tue, Jul 10, 2001 at 09:40:31AM +0100, Mark Muffett wrote:
> Is there a Postgresql equivalent to the Oracle NVL( ) function,
> which allows a SELECT statement to fill in default values if a
> column is NULL?

Yes.

Use the DEFAULT keyword while creating the table.

That is:

    CREATE TABLE account (
    name    CHAR(20),
    balance    NUMERIC(16,2) DEFAULT 0,
    active    CHAR(2) DEFAULT 'Y',
    created TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    );

Then :

    INSERT INTO account (name)
    VALUES ('Federated Builders');

will leave the inserted rows with no nulls, but the balance will be
zero, and the "created" field will have the date/time of the insert.

> Mark Muffett

         -crl
--
Chad R. Larson (CRL22)    chad@eldocomp.com
  Eldorado Computing, Inc.   602-604-3100
     5353 North 16th Street, Suite 400
       Phoenix, Arizona   85016-3228

pgsql-general by date:

Previous
From: "Mark G. Franz"
Date:
Subject: Re: Grab data WHERE table.ID NOT LIKE otherTable.ID
Next
From: Nils Zonneveld
Date:
Subject: Re: Postgresql revisited. Some questions about the product