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 320815292E; Mon, 6 Jun 2005 12:39:58 -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 11831-06; Mon, 6 Jun 2005 15:39:51 +0000 (GMT) Received: from joeconway.com (wsip-24-249-201-67.sd.sd.cox.net [24.249.201.67]) by svr1.postgresql.org (Postfix) with ESMTP id 89B0E52921; Mon, 6 Jun 2005 12:39:49 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO [172.16.1.115]) by joeconway.com (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 2886875; Mon, 06 Jun 2005 09:37:09 -0700 Message-ID: <42A46E44.3060100@joeconway.com> Date: Mon, 06 Jun 2005 08:39:48 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.8) Gecko/20050513 Fedora/1.7.8-1.3.1 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: =?UTF-8?B?TWFya3VzIEJlcnRoZWF1IOKYrQ==?= , pgsql-sql@postgresql.org, pgsql-hackers@postgresql.org Subject: Re: ARRAY() returning NULL instead of ARRAY[] resp. {} References: <1116873219.7306.0.camel@localhost.localdomain> <42923762.7010708@joeconway.com> <16774.1116907560@sss.pgh.pa.us> <1118067445.5506.6.camel@dicaprio.akademie1.de> <25974.1118069089@sss.pgh.pa.us> In-Reply-To: <25974.1118069089@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.048 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200506/84 X-Sequence-Number: 21685 Tom Lane wrote: > Markus Bertheau =?UTF-8?Q?=E2=98=AD?= writes: > >>By analogy, array_upper('{}'::TEXT[], 1) should return 0 instead of >>NULL. > > No, that doesn't follow ... we've traditionally considered '{}' to > denote a zero-dimensional array. A 1-D array of no elements is > '[1:0]={}', just as Joe shows ... or at least it would be except > for an overenthusiastic error check: > > regression=# select '[1:0]={}' :: int[]; > ERROR: upper bound cannot be less than lower bound > > I think this should be a legal boundary case. In general, it should be > possible to form zero-size arrays of any number of dimensions. > I've been playing with exactly this over the weekend. Of course, as usual, the devil is in the details. For instance, using the above notation, how would I specify a zero-element 1D array starting at a lower bound index of 0? The answer following the above pattern would be: select '[0:-1]={}'::int[]; You could not use '[0:0]={}'::int[], because that would be a one-element array. I propose the following instead: regression=# select '[1:]={}' :: int[]; int4 ------ {} (1 row) regression=# select array_dims('[1:]={}' :: int[]); array_dims ------------ [1:] (1 row) In other words, an missing upper bound indicates zero elements. Now the next question; what does a 2D zero-element array look like? I think this makes sense: regression=# select '[1:2][1:]={{},{}}'::int[]; int4 ------ {} (1 row) Except (I think) array_out() should probably output something closer to the input literal. Any thoughts on this? Joe