Tom Lane wrote: > Bruce Momjian <[EMAIL PROTECTED]> 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  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]]) 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 <[EMAIL PROTECTED]> http://momjian.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. +
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] 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] 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></> is treated as ! <literal>[1:2], as in this example: <programlisting> SELECT schedule[1:2] FROM sal_emp WHERE name = 'Bill'; schedule
---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend