pg.ddx.io pgsql-docs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #2913: Subscript on multidimensional array yields no value
8+ messages / 3 participants
[nested] [flat]
* BUG #2913: Subscript on multidimensional array yields no value
@ 2007-01-19 14:50 Roman Nowak <roman_nowak@poczta.onet.pl>
0 siblings, 1 reply; 8+ messages in thread
From: Roman Nowak @ 2007-01-19 14:50 UTC (permalink / raw)
To: pgsql-bugs@postgresql.org
The following bug has been logged online:
Bug reference: 2913
Logged by: Roman Nowak
Email address: roman_nowak@poczta.onet.pl
PostgreSQL version: 8.2.1
Operating system: Windows XP
Description: Subscript on multidimensional array yields no value
Details:
SELECT (ARRAY[[1,2],[3,4]])[1];
does not return [1,2]
(testes in psql and pgAdmin III): show info that one row was returned but
does not display its value
following statment works OK btw
SELECT (ARRAY[[1,2],[3,4]])[1:1];
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #2913: Subscript on multidimensional array yields no value
@ 2007-01-30 22:50 Bruce Momjian <bruce@momjian.us>
parent: Roman Nowak <roman_nowak@poczta.onet.pl>
0 siblings, 1 reply; 8+ messages in thread
From: Bruce Momjian @ 2007-01-30 22:50 UTC (permalink / raw)
To: Roman Nowak <roman_nowak@poczta.onet.pl>; +Cc: pgsql-bugs@postgresql.org
I can confirm this is a bug. Added to the TODO list:
o ARRAY[[1,2],[3,4]])[1] should return the same values as
ARRAY[[1,2],[3,4]])[1:1];
---------------------------------------------------------------------------
Roman Nowak wrote:
>
> The following bug has been logged online:
>
> Bug reference: 2913
> Logged by: Roman Nowak
> Email address: roman_nowak@poczta.onet.pl
> PostgreSQL version: 8.2.1
> Operating system: Windows XP
> Description: Subscript on multidimensional array yields no value
> Details:
>
> SELECT (ARRAY[[1,2],[3,4]])[1];
>
> does not return [1,2]
> (testes in psql and pgAdmin III): show info that one row was returned but
> does not display its value
>
> following statment works OK btw
> SELECT (ARRAY[[1,2],[3,4]])[1:1];
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com
+ If your life is a hard drive, Christ can be your backup. +
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #2913: Subscript on multidimensional array yields no value
@ 2007-01-31 00:19 Tom Lane <tgl@sss.pgh.pa.us>
parent: Bruce Momjian <bruce@momjian.us>
0 siblings, 2 replies; 8+ messages in thread
From: Tom Lane @ 2007-01-31 00:19 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: Roman Nowak <roman_nowak@poczta.onet.pl>; pgsql-bugs@postgresql.org
Bruce Momjian <bruce@momjian.us> writes:
> I can confirm this is a bug. Added to the TODO list:
> o ARRAY[[1,2],[3,4]])[1] should return the same values as
> ARRAY[[1,2],[3,4]])[1:1];
This is not a bug, this is a definitional disagreement, and your TODO
entry presupposes an answer that I don't particularly agree with.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #2913: Subscript on multidimensional array yields no value
@ 2007-01-31 02:00 Bruce Momjian <bruce@momjian.us>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 8+ messages in thread
From: Bruce Momjian @ 2007-01-31 02:00 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Roman Nowak <roman_nowak@poczta.onet.pl>; pgsql-bugs@postgresql.org
Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > I can confirm this is a bug. Added to the TODO list:
> > o ARRAY[[1,2],[3,4]])[1] should return the same values as
> > ARRAY[[1,2],[3,4]])[1:1];
>
> 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
What is the issue here that makes that not true?
--
Bruce Momjian bruce@momjian.us
EnterpriseDB http://www.enterprisedb.com
+ If your life is a hard drive, Christ can be your backup. +
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #2913: Subscript on multidimensional array yields no value
@ 2007-01-31 03:44 Tom Lane <tgl@sss.pgh.pa.us>
parent: Bruce Momjian <bruce@momjian.us>
0 siblings, 2 replies; 8+ messages in thread
From: Tom Lane @ 2007-01-31 03:44 UTC (permalink / raw)
To: Bruce Momjian <bruce@momjian.us>; +Cc: Roman Nowak <roman_nowak@poczta.onet.pl>; pgsql-bugs@postgresql.org
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.
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [BUGS] BUG #2913: Subscript on multidimensional array yields no value
@ 2007-01-31 04:07 Bruce Momjian <bruce@momjian.us>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 8+ messages in thread
From: Bruce Momjian @ 2007-01-31 04:07 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Roman Nowak <roman_nowak@poczta.onet.pl>; pgsql-docs
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. +
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [BUGS] BUG #2913: Subscript on multidimensional array yields no value
@ 2007-02-20 03:46 Bruce Momjian <bruce@momjian.us>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 8+ messages in thread
From: Bruce Momjian @ 2007-02-20 03:46 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Roman Nowak <roman_nowak@poczta.onet.pl>; PostgreSQL-patches <pgsql-patches@postgresql.org>
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.
I finally figured out what you were saying by reading the source code
and finding this comment in parse_node.c:
/*
* A list containing only single subscripts refers to a single array
* element. If any of the items are double subscripts (lower:upper), then
* the subscript expression means an array slice operation. In this case,
* we supply a default lower bound of 1 for any items that contain only a
* single subscript. We have to prescan the indirection list to see if
* there are any double subscripts.
*/
I have updated the array documentation to be clearer about how slices
are handled, patch attached.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com
+ If your life is a hard drive, Christ can be your backup. +
Attachments:
/pgpatches/array (text/x-diff, 1.5K) download
Index: doc/src/sgml/array.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/array.sgml,v
retrieving revision 1.56
diff -c -c -r1.56 array.sgml
*** doc/src/sgml/array.sgml 1 Feb 2007 00:28:16 -0000 1.56
--- doc/src/sgml/array.sgml 20 Feb 2007 03:43:28 -0000
***************
*** 243,260 ****
(1 row)
</programlisting>
! We could also have written:
<programlisting>
- SELECT schedule[1:2][1] FROM sal_emp WHERE name = 'Bill';
- </programlisting>
-
- 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
- <literal><replaceable>lower</replaceable>:<replaceable>upper</replaceable></literal>.
- A lower bound of 1 is assumed for any subscript where only one value
- is specified, as in this example:
- <programlisting>
SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill';
schedule
--- 243,256 ----
(1 row)
</programlisting>
! If any dimmension is written as a slice, i.e contains a colon, then all
! dimmensions are treated as slices. If a dimmension is missing, it is
! assumed to be <literal>[1:1]</>. If a dimmension has only a single
! number (no colon), that dimmension is treated as being from <literal>1</>
! to the number specified. For example, <literal>[2]</> is treated as
! <literal>[1:2], as in this example:
<programlisting>
SELECT schedule[1:2][2] FROM sal_emp WHERE name = 'Bill';
schedule
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG #2913: Subscript on multidimensional array yields no value
@ 2007-02-20 03:47 Bruce Momjian <bruce@momjian.us>
parent: Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 8+ messages in thread
From: Bruce Momjian @ 2007-02-20 03:47 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Roman Nowak <roman_nowak@poczta.onet.pl>; pgsql-bugs@postgresql.org
Tom Lane wrote:
> Bruce Momjian <bruce@momjian.us> writes:
> > I can confirm this is a bug. Added to the TODO list:
> > o ARRAY[[1,2],[3,4]])[1] should return the same values as
> > ARRAY[[1,2],[3,4]])[1:1];
>
> This is not a bug, this is a definitional disagreement, and your TODO
> entry presupposes an answer that I don't particularly agree with.
TODO item removed, now that I understand the array behavior.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com
+ If your life is a hard drive, Christ can be your backup. +
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2007-02-20 03:47 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-01-19 14:50 BUG #2913: Subscript on multidimensional array yields no value Roman Nowak <roman_nowak@poczta.onet.pl>
2007-01-30 22:50 ` Bruce Momjian <bruce@momjian.us>
2007-01-31 00:19 ` Tom Lane <tgl@sss.pgh.pa.us>
2007-01-31 02:00 ` Bruce Momjian <bruce@momjian.us>
2007-01-31 03:44 ` Tom Lane <tgl@sss.pgh.pa.us>
2007-01-31 04:07 ` Bruce Momjian <bruce@momjian.us>
2007-02-20 03:46 ` Bruce Momjian <bruce@momjian.us>
2007-02-20 03:47 ` Bruce Momjian <bruce@momjian.us>
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