1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/array.sgml,v 1.69 2009/04/27 16:27:35 momjian Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/array.sgml,v 1.70 2009/06/17 21:58:48 tgl Exp $ -->
2
2
3
3
<sect1 id="arrays">
4
4
<title>Arrays</title>
@@ -60,18 +60,17 @@ CREATE TABLE tictactoe (
60
60
</para>
61
61
62
62
<para>
63
- In addition, the current implementation does not enforce the declared
63
+ The current implementation does not enforce the declared
64
64
number of dimensions either. Arrays of a particular element type are
65
65
all considered to be of the same type, regardless of size or number
66
- of dimensions. So, declaring the number of dimensions or sizes in
67
- <command>CREATE TABLE</command> is simply documentation, it does not
66
+ of dimensions. So, declaring the array size or number of dimensions in
67
+ <command>CREATE TABLE</command> is simply documentation; it does not
68
68
affect run-time behavior.
69
69
</para>
70
70
71
71
<para>
72
72
An alternative syntax, which conforms to the SQL standard by using
73
- they keyword <literal>ARRAY</>, can
74
- be used for one-dimensional arrays;
73
+ the keyword <literal>ARRAY</>, can be used for one-dimensional arrays.
75
74
<structfield>pay_by_quarter</structfield> could have been defined
76
75
as:
77
76
<programlisting>
@@ -109,7 +108,7 @@ CREATE TABLE tictactoe (
109
108
for the type, as recorded in its <literal>pg_type</literal> entry.
110
109
Among the standard data types provided in the
111
110
<productname>PostgreSQL</productname> distribution, all use a comma
112
- (<literal>,</>), except for the type <literal >box</> which uses a semicolon
111
+ (<literal>,</>), except for type <type >box</> which uses a semicolon
113
112
(<literal>;</>). Each <replaceable>val</replaceable> is
114
113
either a constant of the array element type, or a subarray. An example
115
114
of an array constant is:
@@ -121,7 +120,7 @@ CREATE TABLE tictactoe (
121
120
</para>
122
121
123
122
<para>
124
- To set an element of an array to NULL, write <literal>NULL</>
123
+ To set an element of an array constant to NULL, write <literal>NULL</>
125
124
for the element value. (Any upper- or lower-case variant of
126
125
<literal>NULL</> will do.) If you want an actual string value
127
126
<quote>NULL</>, you must put double quotes around it.
@@ -211,7 +210,7 @@ INSERT INTO sal_emp
211
210
First, we show how to access a single element of an array.
212
211
This query retrieves the names of the employees whose pay changed in
213
212
the second quarter:
214
-
213
+
215
214
<programlisting>
216
215
SELECT name FROM sal_emp WHERE pay_by_quarter[1] <> pay_by_quarter[2];
217
216
@@ -230,7 +229,7 @@ SELECT name FROM sal_emp WHERE pay_by_quarter[1] <> pay_by_quarter[2];
230
229
231
230
<para>
232
231
This query retrieves the third quarter pay of all employees:
233
-
232
+
234
233
<programlisting>
235
234
SELECT pay_by_quarter[3] FROM sal_emp;
236
235
@@ -248,7 +247,7 @@ SELECT pay_by_quarter[3] FROM sal_emp;
248
247
<literal><replaceable>lower-bound</replaceable>:<replaceable>upper-bound</replaceable></literal>
249
248
for one or more array dimensions. For example, this query retrieves the first
250
249
item on Bill's schedule for the first two days of the week:
251
-
250
+
252
251
<programlisting>
253
252
SELECT schedule[1:2][1:1] FROM sal_emp WHERE name = 'Bill';
254
253
@@ -417,14 +416,14 @@ SELECT ARRAY[5,6] || ARRAY[[1,2],[3,4]];
417
416
</para>
418
417
419
418
<para>
420
- The concatenation operator allows a single element to be pushed to the
419
+ The concatenation operator allows a single element to be pushed onto the
421
420
beginning or end of a one-dimensional array. It also accepts two
422
421
<replaceable>N</>-dimensional arrays, or an <replaceable>N</>-dimensional
423
422
and an <replaceable>N+1</>-dimensional array.
424
423
</para>
425
424
426
425
<para>
427
- When a single element is pushed to either the beginning or end of a
426
+ When a single element is pushed onto either the beginning or end of a
428
427
one-dimensional array, the result is an array with the same lower bound
429
428
subscript as the array operand. For example:
430
429
<programlisting>
@@ -463,7 +462,7 @@ SELECT array_dims(ARRAY[[1,2],[3,4]] || ARRAY[[5,6],[7,8],[9,0]]);
463
462
</para>
464
463
465
464
<para>
466
- When an <replaceable>N</>-dimensional array is pushed to the beginning
465
+ When an <replaceable>N</>-dimensional array is pushed onto the beginning
467
466
or end of an <replaceable>N+1</>-dimensional array, the result is
468
467
analogous to the element-array case above. Each <replaceable>N</>-dimensional
469
468
sub-array is essentially an element of the <replaceable>N+1</>-dimensional
@@ -601,9 +600,9 @@ SELECT * FROM
601
600
around the array value plus delimiter characters between adjacent items.
602
601
The delimiter character is usually a comma (<literal>,</>) but can be
603
602
something else: it is determined by the <literal>typdelim</> setting
604
- for the array's element type. ( Among the standard data types provided
605
- in the <productname>PostgreSQL</productname> distribution, all
606
- use a comma, except for <literal >box</>, which uses a semicolon (<literal>;</>).)
603
+ for the array's element type. Among the standard data types provided
604
+ in the <productname>PostgreSQL</productname> distribution, all use a comma,
605
+ except for type <type >box</>, which uses a semicolon (<literal>;</>).
607
606
In a multidimensional array, each dimension (row, plane,
608
607
cube, etc.) gets its own level of curly braces, and delimiters
609
608
must be written between adjacent curly-braced entities of the same level.
@@ -657,7 +656,7 @@ SELECT f1[1][-2][3] AS e1, f1[1][-1][5] AS e2
657
656
As shown previously, when writing an array value you can use double
658
657
quotes around any individual array element. You <emphasis>must</> do so
659
658
if the element value would otherwise confuse the array-value parser.
660
- For example, elements containing curly braces, commas (or the matching
659
+ For example, elements containing curly braces, commas (or the data type's
661
660
delimiter character), double quotes, backslashes, or leading or trailing
662
661
whitespace must be double-quoted. Empty strings and strings matching the
663
662
word <literal>NULL</> must be quoted, too. To put a double quote or
@@ -668,7 +667,7 @@ SELECT f1[1][-2][3] AS e1, f1[1][-1][5] AS e2
668
667
</para>
669
668
670
669
<para>
671
- You can use whitespace before a left brace or after a right
670
+ You can add whitespace before a left brace or after a right
672
671
brace. You can also add whitespace before or after any individual item
673
672
string. In all of these cases the whitespace will be ignored. However,
674
673
whitespace within double-quoted elements, or surrounded on both sides by
0 commit comments