X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 547555287F for ; Tue, 24 May 2005 01:06:19 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 14971-02 for ; Tue, 24 May 2005 04:06:07 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 1522C5283A for ; Tue, 24 May 2005 01:06:03 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j4O4605Q016775; Tue, 24 May 2005 00:06:00 -0400 (EDT) To: Joe Conway Cc: Markus Bertheau , pgsql-sql@postgresql.org Subject: Re: ARRAY() returning NULL instead of ARRAY[] resp. {} In-reply-to: <42923762.7010708@joeconway.com> References: <1116873219.7306.0.camel@localhost.localdomain> <42923762.7010708@joeconway.com> Comments: In-reply-to Joe Conway message dated "Mon, 23 May 2005 13:04:50 -0700" Date: Tue, 24 May 2005 00:06:00 -0400 Message-ID: <16774.1116907560@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/193 X-Sequence-Number: 21506 Joe Conway 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