From: Tom Lane <tgl@sss.pgh.pa.us>
To: Joe Conway <mail@joeconway.com>
Cc: Markus Bertheau <twanger@bluetwanger.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: ARRAY() returning NULL instead of ARRAY[] resp. {}
Date: Tue, 24 May 2005 00:06:00 -0400
Message-ID: <16774.1116907560@sss.pgh.pa.us> (raw)
In-Reply-To: <42923762.7010708@joeconway.com>
References: <1116873219.7306.0.camel@localhost.localdomain>
<42923762.7010708@joeconway.com>
Joe Conway <mail@joeconway.com> writes:
> Markus Bertheau wrote:
>> why does SELECT ARRAY(SELECT 1 WHERE FALSE) return NULL instead of
>> ARRAY[] resp. '{}'?
> Why would you expect an empty array instead of a NULL?
I think he's got a good point, actually. We document the ARRAY-with-
parens-around-a-SELECT syntax as
The resulting one-dimensional array will have an element for
each row in the subquery result, with an element type matching
that of the subquery's output column.
To me, that implies that a subquery result of no rows generates a
one-dimensional array of no elements, not a null array.
This is not the same as
SELECT ARRAY[(SELECT 1 WHERE FALSE)];
We define a scalar subquery that returns no rows as returning null, so
this is equivalent to
SELECT ARRAY[NULL];
which *ought* to yield an array containing a single NULL element,
but since we can't yet handle arrays containing nulls we punt and
return a null array value. That's wrong too ... but it's a different
issue. The point Markus is complaining about seems like it should
be easily fixable.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, mail@joeconway.com, twanger@bluetwanger.de
Subject: Re: ARRAY() returning NULL instead of ARRAY[] resp. {}
In-Reply-To: <16774.1116907560@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox