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)    [EMAIL PROTECTED]
  Eldorado Computing, Inc.   602-604-3100
     5353 North 16th Street, Suite 400
       Phoenix, Arizona   85016-3228

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to