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

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Jonathan Moules <jonathan-lists(at)lightpear(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Always getting back a row, even with no results
Date: 2017-08-11 15:18:04
Message-ID: CAKFQuwYxL33=Az3EiH-=1-R1cHLSs98zUDvtcLgZDURoc3wYHQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Aug 11, 2017 at 6:57 AM, Jonathan Moules <
jonathan-lists(at)lightpear(dot)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.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jonathan Moules 2017-08-11 15:30:35 Re: Always getting back a row, even with no results
Previous Message Achilleas Mantzios 2017-08-11 14:28:47 Re: Always getting back a row, even with no results