Providing an alternative result when there is no result

Поиск
Список
Период
Сортировка
От Joshua Berry
Тема Providing an alternative result when there is no result
Дата
Msg-id F7CBFA5D-5253-44C6-9CCE-59BF236FE0D8@gmail.com
обсуждение исходный текст
Ответы Re: Providing an alternative result when there is no result  (Pavel Stehule <pavel.stehule@gmail.com>)
Re: Providing an alternative result when there is no result  (Martijn van Oosterhout <kleptog@svana.org>)
Re: Providing an alternative result when there is no result  (David Wilson <david.t.wilson@gmail.com>)
Re: Providing an alternative result when there is no result  (Reece Hart <reece@harts.net>)
Re: Providing an alternative result when there is no result  (David Fetter <david@fetter.org>)
Re: Providing an alternative result when there is no result  (Merlin Moncure <mmoncure@gmail.com>)
Список pgsql-general
Hello all,

Is there an easy and efficient way to return a boolean false for a
query that returns no result, and true for one that does return a
result?

Currently we select the result into a temp table.

SELECT INTO temp_table id FROM ... ;
IF temp_table IS NULL THEN
resp:= 'NO';
ELSE
resp:= 'YES';
END IF;

I'd like to combine this into one step like this:
SELECT
   CASE
     WHEN id is null THEN 'NO'::text
     ELSE 'YES'::text
   END
FROM ...;

But, this is not have SELECT's work, I suppose. The CASE is never
encountered when there is no result, so in the "NO" case, NULL is
returned.

Any hints/tips? Is our original solution okay, or is there something
we can do to improve things?

Thanks,

Joshua Berry

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

Предыдущее
От: Zico
Дата:
Сообщение: Re: Need help
Следующее
От: Pavel Stehule
Дата:
Сообщение: Re: Providing an alternative result when there is no result