Re: [BUGS] BUG #2913: Subscript on multidimensional array yields no value

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Roman Nowak <roman_nowak(at)poczta(dot)onet(dot)pl>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #2913: Subscript on multidimensional array yields no value
Date: 2007-02-20 03:46:35
Message-ID: 200702200346.l1K3kZw21699@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-docs pgsql-patches

Tom Lane wrote:
> Bruce Momjian <bruce(at)momjian(dot)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(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
/pgpatches/array text/x-diff 1.5 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2007-02-20 03:47:23 Re: BUG #2913: Subscript on multidimensional array yields no value
Previous Message Tom Lane 2007-02-20 03:42:38 Re: BUG #3031: PHP (and others?) cannot close a connection when "in" a COPY-statement

Browse pgsql-docs by date

  From Date Subject
Next Message Bruce Momjian 2007-02-20 03:47:23 Re: BUG #2913: Subscript on multidimensional array yields no value
Previous Message Bruce Momjian 2007-02-19 18:57:45 Re: Online documentation unclear about authentication defaults

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2007-02-20 03:47:23 Re: BUG #2913: Subscript on multidimensional array yields no value
Previous Message Tom Lane 2007-02-20 03:44:06 Re: [PATCHES] WIP patch - INSERT-able log statements