Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id C07589FB35D for ; Wed, 31 Jan 2007 00:07:15 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 80638-06 for ; Wed, 31 Jan 2007 00:07:12 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from momjian.us (momjian.us [70.90.9.53]) by postgresql.org (Postfix) with ESMTP id 8EA7C9FB349 for ; Wed, 31 Jan 2007 00:07:12 -0400 (AST) Received: (from bruce@localhost) by momjian.us (8.11.6/8.11.6) id l0V47B317659; Tue, 30 Jan 2007 23:07:11 -0500 (EST) From: Bruce Momjian Message-Id: <200701310407.l0V47B317659@momjian.us> Subject: Re: [BUGS] BUG #2913: Subscript on multidimensional array yields no value In-Reply-To: <14949.1170215057@sss.pgh.pa.us> To: Tom Lane Date: Tue, 30 Jan 2007 23:07:11 -0500 (EST) CC: Roman Nowak , PostgreSQL-documentation X-Mailer: ELM [version 2.4ME+ PL123] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/34 X-Sequence-Number: 4130 Tom Lane wrote: > Bruce Momjian writes: > > Tom Lane wrote: > >> This is not a bug, this is a definitional disagreement, and your TODO > >> entry presupposes an answer that I don't particularly agree with. > > > Well, our documentation suggests thaat [1] is the same as [1:1]: > > http://www.postgresql.org/docs/8.2/static/arrays.html#AEN5791 > > It says absolutely no such thing. A subscript expression involving m:n > produces a "slice", hence an array of different dimensionality from the > original, whereas a subscript expression not involving any colon > produces a single element --- that is, not an array at all. > > You could make a fair case that the (ARRAY[[1,2],[3,4]])[1] example > should throw an error instead of returning null. But to claim it is > the same as a slice expression is a typing violation. [ moved to docs list ] Well, I don't understand our array documentation, so odds are others don't either. What are we saying here: An array slice is denoted by writing lower-bound:upper-bound for one or more array dimensions. For example, this query retrieves the first item on Bill's schedule for the first two days of the week: SELECT schedule[1:2][1:1] FROM sal_emp WHERE name = 'Bill'; schedule ------------------------ {{meeting},{training}} (1 row) We could also have written SELECT schedule[1:2][1] FROM sal_emp WHERE name = 'Bill'; with the same result. An array subscripting operation is always taken to represent an array slice if any of the subscripts are written in the form lower:upper. A lower bound of 1 is assumed for any subscript where only one value is specified, as in this example: What is the difference between 'lower-bound:upper-bound' and 'lower:upper'? Here are the items that confuse me: test=> SELECT (ARRAY[[1,2],[3,4]])[1][1]; array ------- 1 (1 row) test=> SELECT (ARRAY[[1,2],[3,4]])[1:1]; array --------- {{1,2}} (1 row) test=> SELECT (ARRAY[[1,2],[3,4]])[1]; array ------- (1 row) The first two make sense to me, but the last one does not. If someone explains it, I can update our documentation. -- Bruce Momjian bruce@momjian.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. +