Re: [SQL] Always getting back a row, even with no results - Mailing list pgsql-sql

From David G. Johnston
Subject Re: [SQL] Always getting back a row, even with no results
Date
Msg-id CAKFQuwYxL33=Az3EiH-=1-R1cHLSs98zUDvtcLgZDURoc3wYHQ@mail.gmail.com
Whole thread Raw
In response to [SQL] Always getting back a row, even with no results  (Jonathan Moules <jonathan-lists@lightpear.com>)
Responses Re: [SQL] Always getting back a row, even with no results  (Jonathan Moules <jonathan-lists@lightpear.com>)
List pgsql-sql
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 by date:

Previous
From: Achilleas Mantzios
Date:
Subject: Re: [SQL] Always getting back a row, even with no results
Next
From: Jonathan Moules
Date:
Subject: Re: [SQL] Always getting back a row, even with no results