Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit432fb5b

Browse files
committed
Updates for array documentation, from Joe Conway.
1 parent80860c3 commit432fb5b

File tree

3 files changed

+85
-23
lines changed

3 files changed

+85
-23
lines changed

‎doc/src/sgml/array.sgml

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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>
328327
SELECT 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

334333
SELECT 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>
356355
SELECT 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

388428
SELECT 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

394434
SELECT array_cat(ARRAY[[1,2],[3,4]], ARRAY[5,6]);

‎doc/src/sgml/func.sgml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.167 2003/08/17 04:52:41 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.168 2003/08/19 06:06:43 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -7032,7 +7032,7 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
70327032

70337033
<para>
70347034
<xref linkend="array-operators-table"> shows the operators
7035-
available forthe<type>array</type> types.
7035+
available for <type>array</type> types.
70367036
</para>
70377037

70387038
<table id="array-operators-table">
@@ -7093,7 +7093,7 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
70937093
<entry> <literal>||</literal> </entry>
70947094
<entry>array-to-array concatenation</entry>
70957095
<entry><literal>ARRAY[1,2,3] || ARRAY[4,5,6]</literal></entry>
7096-
<entry><literal>{{1,2,3},{4,5,6}}</literal></entry>
7096+
<entry><literal>{1,2,3,4,5,6}</literal></entry>
70977097
</row>
70987098

70997099
<row>
@@ -7120,6 +7120,11 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
71207120
</tgroup>
71217121
</table>
71227122

7123+
<para>
7124+
See <xref linkend="arrays"> for more details about array operator
7125+
behavior.
7126+
</para>
7127+
71237128
<para>
71247129
<xref linkend="array-functions-table"> shows the functions
71257130
available for use with array types. See <xref linkend="arrays">
@@ -7167,7 +7172,7 @@ SELECT pg_type_is_visible('myschema.widget'::regtype);
71677172
for <literal>NULL</literal> inputs
71687173
</entry>
71697174
<entry><literal>array_cat(ARRAY[1,2,3], ARRAY[4,5,6])</literal></entry>
7170-
<entry><literal>{{1,2,3},{4,5,6}}</literal></entry>
7175+
<entry><literal>{1,2,3,4,5,6}</literal></entry>
71717176
</row>
71727177
<row>
71737178
<entry>

‎doc/src/sgml/syntax.sgml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.82 2003/08/14 23:13:27 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.83 2003/08/19 06:06:48 tgl Exp $
33
-->
44

55
<chapter id="sql-syntax">
@@ -1270,6 +1270,23 @@ SELECT ARRAY[[1,2],[3,4]];
12701270
at the same level must produce sub-arrays of identical dimensions.
12711271
</para>
12721272

1273+
<para>
1274+
Multidimensional array constructor elements can be anything yielding
1275+
an array of the proper kind, not only a sub-<literal>ARRAY</> construct.
1276+
For example:
1277+
<programlisting>
1278+
create table arr(f1 int[], f2 int[]);
1279+
CREATE TABLE
1280+
insert into arr values (ARRAY[[1,2],[3,4]],ARRAY[[5,6],[7,8]]);
1281+
INSERT 2635544 1
1282+
select ARRAY[f1, f2, '{{9,10},{11,12}}'::int[]] from arr;
1283+
array
1284+
------------------------------------------------
1285+
{{{1,2},{3,4}},{{5,6},{7,8}},{{9,10},{11,12}}}
1286+
(1 row)
1287+
</programlisting>
1288+
</para>
1289+
12731290
<para>
12741291
It is also possible to construct an array from the results of a
12751292
subquery. In this form, the array constructor is written with the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp