1- <!-- $Header: /cvsroot/pgsql/doc/src/sgml/array.sgml,v 1.29 2003/08/09 22:50:21 tgl Exp $ -->
1+ <!-- $Header: /cvsroot/pgsql/doc/src/sgml/array.sgml,v 1.30 2003/08/19 06:06:43 tgl Exp $ -->
22
33<sect1 id="arrays">
44 <title>Arrays</title>
@@ -162,7 +162,6 @@ ERROR: multidimensional arrays must have array expressions with matching dimens
162162 expression syntax is discussed in more detail in <xref
163163 linkend="sql-syntax-array-constructors">.
164164 </para>
165-
166165 </sect2>
167166
168167 <sect2>
@@ -326,9 +325,9 @@ UPDATE sal_emp SET pay_by_quarter[1:2] = '{27000,27000}'
326325 <literal>||</literal>.
327326<programlisting>
328327SELECT ARRAY[1,2] || ARRAY[3,4];
329- ?column?
330- ---------------
331- {{ 1,2},{ 3,4} }
328+ ?column?
329+ -----------
330+ {1,2, 3,4}
332331(1 row)
333332
334333SELECT ARRAY[5,6] || ARRAY[[1,2],[3,4]];
@@ -337,27 +336,68 @@ SELECT ARRAY[5,6] || ARRAY[[1,2],[3,4]];
337336 {{5,6},{1,2},{3,4}}
338337(1 row)
339338</programlisting>
339+ </para>
340340
341+ <para>
341342 The concatenation operator allows a single element to be pushed on to the
342343 beginning or end of a one-dimensional array. It also accepts two
343344 <replaceable>N</>-dimensional arrays, or an <replaceable>N</>-dimensional
344- and an <replaceable>N+1</>-dimensional array. In the former case, the two
345- <replaceable>N</>-dimension arrays become outer elements of an
346- <replaceable>N+1</>-dimensional array. In the latter, the
347- <replaceable>N</>-dimensional array is added as either the first or last
348- outer element of the <replaceable>N+1</>-dimensional array.
349-
350- When extending an array by concatenation, the subscripts of its existing
351- elements are preserved. For example, when pushing
352- onto the beginning of an array with one-based subscripts, the resulting
353- array has zero-based subscripts:
345+ and an <replaceable>N+1</>-dimensional array.
346+ </para>
354347
348+ <para>
349+ When a single element is pushed on to the beginning of a one-dimensional
350+ array, the result is an array with a lower bound subscript equal to
351+ the righthand operand's lower bound subscript, minus one. When a single
352+ element is pushed on to the end of a one-dimensional array, the result is
353+ an array retaining the lower bound of the lefthand operand. For example:
355354<programlisting>
356355SELECT array_dims(1 || ARRAY[2,3]);
357356 array_dims
358357------------
359358 [0:2]
360359(1 row)
360+
361+ SELECT array_dims(ARRAY[1,2] || 3);
362+ array_dims
363+ ------------
364+ [1:3]
365+ (1 row)
366+ </programlisting>
367+ </para>
368+
369+ <para>
370+ When two arrays with an equal number of dimensions are concatenated, the
371+ result retains the lower bound subscript of the lefthand operand's outer
372+ dimension. The result is an array comprising every element of the lefthand
373+ operand followed by every element of the righthand operand. For example:
374+ <programlisting>
375+ SELECT array_dims(ARRAY[1,2] || ARRAY[3,4,5]);
376+ array_dims
377+ ------------
378+ [1:5]
379+ (1 row)
380+
381+ SELECT array_dims(ARRAY[[1,2],[3,4]] || ARRAY[[5,6],[7,8],[9,0]]);
382+ array_dims
383+ ------------
384+ [1:5][1:2]
385+ (1 row)
386+ </programlisting>
387+ </para>
388+
389+ <para>
390+ When an <replaceable>N</>-dimensional array is pushed on to the beginning
391+ or end of an <replaceable>N+1</>-dimensional array, the result is
392+ analogous to the element-array case above. Each <replaceable>N</>-dimensional
393+ sub-array is essentially an element of the <replaceable>N+1</>-dimensional
394+ array's outer dimension. For example:
395+ <programlisting>
396+ SELECT array_dims(ARRAY[1,2] || ARRAY[[3,4],[5,6]]);
397+ array_dims
398+ ------------
399+ [0:2][1:2]
400+ (1 row)
361401</programlisting>
362402 </para>
363403
@@ -386,9 +426,9 @@ SELECT array_append(ARRAY[1,2], 3);
386426(1 row)
387427
388428SELECT array_cat(ARRAY[1,2], ARRAY[3,4]);
389- array_cat
390- ---------------
391- {{ 1,2},{ 3,4} }
429+ array_cat
430+ -----------
431+ {1,2, 3,4}
392432(1 row)
393433
394434SELECT array_cat(ARRAY[[1,2],[3,4]], ARRAY[5,6]);