From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | David Salisbury <salisbury(at)globe(dot)gov> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: default value returned from sql stmt |
Date: | 2012-03-29 22:28:09 |
Message-ID: | CAFj8pRCs3Evr1=_pTxYG6xqH3s8oZ_n-hm5dw16-Fxs1oYQdCg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hello
2012/3/30 David Salisbury <salisbury(at)globe(dot)gov>:
>
> 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)
select anum from t1 where anum = 4
union all select 100 limit 1;
Regards
Pavel
>
> Do I have to resort to PLPGSQL for this?
>
> thanks for any info,
>
> -ds
>
> oh.. running 9.1
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
From | Date | Subject | |
---|---|---|---|
Next Message | David Salisbury | 2012-03-29 22:56:36 | Re: default value returned from sql stmt |
Previous Message | Chris Angelico | 2012-03-29 22:26:37 | Re: default value returned from sql stmt |