Re: How to return a default value if no result

Поиск
Список
Период
Сортировка
От Rob - TEAM Systems Ltd
Тема Re: How to return a default value if no result
Дата
Msg-id 004001cfbe1e$4b757940$e2606bc0$@teamsystems.co.uk
обсуждение исходный текст
Ответ на Re: How to return a default value if no result  (David G Johnston <david.g.johnston@gmail.com>)
Ответы Re: How to return a default value if no result  (David G Johnston <david.g.johnston@gmail.com>)
Список pgsql-novice
Thanks David,
That's actually what we did in the end, works fine in the case where there
is only one field (sorry, column!) in the result.
Just out of curiosity (luckily all the places I need to do this at the
moment will work with coalesce), is there a way to return a default result
with a multiple-column query, without resorting to unions or the long-winded
case statement?
Something like this would be nice (but I don't think such a syntax exists,
at least not that I can find):
SELECT col1, col2, col3 FROM mytable
WHERE key='A'
DEFAULT (0,'No','')


-----Original Message-----
From: pgsql-novice-owner@postgresql.org
[mailto:pgsql-novice-owner@postgresql.org] On Behalf Of David G Johnston
Sent: 22 August 2014 15:07
To: pgsql-novice@postgresql.org
Subject: Re: [NOVICE] How to return a default value if no result

Rob Northcott wrote
> Is there a nice way of forcing a default result somehow?

The Coalesce function is your friend:

SELECT COALESCE( (SELECT subquery), <default> )

David J.



--
View this message in context:
http://postgresql.1045698.n5.nabble.com/How-to-return-a-default-value-if-no-
result-tp5815850p5815860.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.


--
Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org) To make
changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice




В списке pgsql-novice по дате отправления:

Предыдущее
От: David G Johnston
Дата:
Сообщение: Re: How to return a default value if no result
Следующее
От: David G Johnston
Дата:
Сообщение: Re: How to return a default value if no result