Re: [SQL] Always getting back a row, even with no results

Поиск
Список
Период
Сортировка
От Jonathan Moules
Тема Re: [SQL] Always getting back a row, even with no results
Дата
Msg-id 15dd1ef824a.11e71b280106536.5163340769196231808@lightpear.com
обсуждение исходный текст
Ответ на Re: [SQL] Always getting back a row, even with no results  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: [SQL] Always getting back a row, even with no results
Список pgsql-sql
Hi David,
I'm afraid I don't really understand this response (I've not done much with arrays), but it doesn't seem to work for my purpose.

No NULL is returned if there is no result (i.e. cat = 50); instead, there's simply no rows.

What aspect of Arrays is this trying to take advantage of?
Cheers,
Jonathan

---- On Fri, 11 Aug 2017 16:18:04 +0100 David G. Johnston<david.g.johnston@gmail.com> wrote ----
On Fri, Aug 11, 2017 at 6:57 AM, Jonathan Moules <jonathan-lists@lightpear.com> wrote:
This will of course return the two rows with that category. But I also want to be able to run the query with a non-existent cat and get a result of "null" for the id.

​untested​

​SELECT unnest( ARRAY( (​
 select id from my_table where cat = 50
​​ ) ) );

tested, self-contained, example:

SELECT unnest(ARRAY((SELECT col FROM ( VALUES (1), (2) ) vals (col) WHERE true)))

David J.



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

Предыдущее
От: Jonathan Moules
Дата:
Сообщение: Re: [SQL] Always getting back a row, even with no results
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: [SQL] Always getting back a row, even with no results