Re: Default value if query returns 0 rows?

Поиск
Список
Период
Сортировка
От Edmund Bacon
Тема Re: Default value if query returns 0 rows?
Дата
Msg-id tmE2d.435990$M95.339884@pd7tw1no
обсуждение исходный текст
Ответ на Default value if query returns 0 rows?  (Lars Kellogg-Stedman <lars@oddbit.com>)
Список pgsql-general
Tom Lane wrote:


> Is the name unique?  If so you could do
>
> select * from
> (select id from map where name = 'foo'
> union all
> select -1) ss
> limit 1;
>
>
> Another way is a subselect:
>
> select coalesce((select id from map where name = 'foo'), -1);
>
> but this one will actively blow up if there are multiple 'foo' rows,
> so it doesn't solve that problem either.

Can't you just:

select coalesce(id, -1) from map where name = 'foo' ?

Or am I missing something?

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

Предыдущее
От: Lars Kellogg-Stedman
Дата:
Сообщение: Re: Default value if query returns 0 rows?
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: How to find a column name