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 5BDB952906 for ; Sat, 4 Jun 2005 14:55:01 -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 16119-03 for ; Sat, 4 Jun 2005 17:54:59 +0000 (GMT) Received: from candle.pha.pa.us (candle.pha.pa.us [64.139.89.126]) by svr1.postgresql.org (Postfix) with ESMTP id 22758528A8 for ; Sat, 4 Jun 2005 14:54:58 -0300 (ADT) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.11.6) id j54HqGZ12891; Sat, 4 Jun 2005 13:52:16 -0400 (EDT) From: Bruce Momjian Message-Id: <200506041752.j54HqGZ12891@candle.pha.pa.us> Subject: Re: ARRAY() returning NULL instead of ARRAY[] resp. {} In-Reply-To: <42961E44.7040701@joeconway.com> To: Joe Conway Date: Sat, 4 Jun 2005 13:52:16 -0400 (EDT) Cc: Tom Lane , Markus Bertheau , pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL121 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.009 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200506/59 X-Sequence-Number: 21660 Joe Conway wrote: > Tom Lane wrote: > > 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. > > OK, looks like I'm outnumbered. > > But as far as I know, we have never had a way to produce a > one-dimensional empty array. Empty arrays thus far have been dimensionless. > > Assuming we really want an empty 1D array, I created the attached patch. > This works fine, but now leaves a few oddities to be dealt with, e.g.: > > regression=# select array_dims(array(select 1 where false)); > array_dims > ------------ > [1:0] > (1 row) > > Any thoughts on how this should be handled for an empty 1D array? > > > The point Markus is complaining about seems like it should > > be easily fixable. > > Well, "easily" is a relative term. My Postgres hacking neurons have > gotten kind of rusty lately -- but then maybe that was your underlying > point ;-) No one responed to this email, so I will try. Is this the one dimmentional array you were talking about? test=> select array_dims('{}'::integer[]); array_dims ------------ (1 row) Why is [1:0] wrong to return? -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073