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

From: Jonathan Moules <jonathan-lists(at)lightpear(dot)com>
To: David G(dot) Johnston <david(dot)g(dot)johnston(at)gmail(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:36:21
Message-ID: 15dd1ef824a.11e71b280106536.5163340769196231808@lightpear.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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&lt;david(dot)g(dot)johnston(at)gmail(dot)com&gt; wrote ----

On Fri, Aug 11, 2017 at 6:57 AM, Jonathan Moules &lt;jonathan-lists(at)lightpear(dot)com&gt; 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 David G. Johnston 2017-08-11 15:43:27 Re: Always getting back a row, even with no results
Previous Message Jonathan Moules 2017-08-11 15:30:35 Re: Always getting back a row, even with no results