default value returned from sql stmt

From: David Salisbury <salisbury(at)globe(dot)gov>
To: pgsql-general(at)postgresql(dot)org
Subject: default value returned from sql stmt
Date: 2012-03-29 22:16:23
Message-ID: 4F74DF37.3070504@globe.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


In trying to get an sql stmt to return a default value, I read in the docs..

"The COALESCE function returns the first of its arguments that is not null. Null is returned only if all arguments are null. It is
often used to substitute a default value for null values when data is retrieved for display, for example:
SELECT COALESCE(description, short_description, '(none)') ..."

But I seem to be missing something:

development=# create table t1 ( anum integer );
CREATE TABLE

development=# insert into t1 values ( 2 ), (3);
INSERT 0 2

development=# select * from t1;

anum
------
2
3

development=# select coalesce(anum,100) from t1 where anum = 4;
coalesce
----------
(0 rows)

Do I have to resort to PLPGSQL for this?

thanks for any info,

-ds

oh.. running 9.1

Responses

Browse pgsql-general by date

  From Date Subject
Next Message BrunoSteven 2012-03-29 22:21:56 Problem to change COLLATE
Previous Message John R Pierce 2012-03-29 21:22:45 Re: Managing two sets of data in one database