Re: default value returned from sql stmt

From: Chris Angelico <rosuav(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: default value returned from sql stmt
Date: 2012-03-29 22:26:37
Message-ID: CAPTjJmqXdFXvtFh5PGGCXarcK+B=JqyvZB4kopNN25z50g=qhw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Mar 30, 2012 at 9:16 AM, David Salisbury <salisbury(at)globe(dot)gov> wrote:
> development=# select  coalesce(anum,100) from t1 where anum = 4;

What you have there is rather different from COALESCE, as you're
looking for a case where the row completely doesn't exist. But you can
fudge it with an outer join.

Untested code:

WITH rowid AS (select 4 as anum) SELECT coalesce(anum,100) FROM rowid
LEFT JOIN t1 ON rowid.anum=t1.anum

However, you may simply want a WHERE [NOT] EXISTS predicate. There may
be other ways of achieving your goal, too.

ChrisA

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2012-03-29 22:28:09 Re: default value returned from sql stmt
Previous Message BrunoSteven 2012-03-29 22:21:56 Problem to change COLLATE