From: Bruce Momjian <bruce@momjian.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Roman Nowak <roman_nowak@poczta.onet.pl>
Cc: PostgreSQL-documentation <pgsql-docs@postgresql.org>
Subject: Re: [BUGS] BUG #2913: Subscript on multidimensional array yields no value
Date: Tue, 30 Jan 2007 23:07:11 -0500 (EST)
Message-ID: <200701310407.l0V47B317659@momjian.us> (raw)
In-Reply-To: <14949.1170215057@sss.pgh.pa.us>
Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> 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. +
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-docs@postgresql.org
Cc: bruce@momjian.us, tgl@sss.pgh.pa.us, roman_nowak@poczta.onet.pl
Subject: Re: [BUGS] BUG #2913: Subscript on multidimensional array yields no value
In-Reply-To: <200701310407.l0V47B317659@momjian.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