Обсуждение: NULL values

Поиск
Список
Период
Сортировка

NULL values

От
"Mark Muffett"
Дата:
A simple question:
 
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?
 
Thanks for any help
 
Mark Muffett

Re: NULL values

От
"Chad R. Larson"
Дата:
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