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

Commite4eb910

Browse files
committed
Document the array_dims() function, and make some other small improvements
in the docs for arrays.
1 parent1f159e5 commite4eb910

File tree

3 files changed

+45
-18
lines changed

3 files changed

+45
-18
lines changed

‎doc/src/sgml/advanced.sgml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.16 2000/09/29 20:21:33 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/advanced.sgml,v 1.17 2000/12/18 23:39:37 tgl Exp $
33
-->
44

55
<chapter id="advanced">
@@ -178,7 +178,7 @@ CREATE TABLE SAL_EMP (
178178
salary by quarter and a two-dimensional array of
179179
<firstterm>text</firstterm>
180180
(schedule), which represents the employee's weekly
181-
schedule. Now we do some <firstterm>INSERTS</firstterm>s;
181+
schedule. Now we do some <firstterm>INSERT</firstterm>s;
182182
note that when
183183
appending to an array, we enclose the values within
184184
braces and separate them by commas. If you know
@@ -239,8 +239,9 @@ SELECT SAL_EMP.pay_by_quarter[3] FROM SAL_EMP;
239239
</para>
240240

241241
<para>
242-
We can also access arbitrary slices of an array, or
243-
subarrays. This query retrieves the first item on
242+
We can also access arbitrary slices of an array (subarrays)
243+
by specifying both lower and upper bounds for
244+
each subscript. This query retrieves the first item on
244245
Bill's schedule for the first two days of the week.
245246

246247
<programlisting>

‎doc/src/sgml/array.sgml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
$Header: /cvsroot/pgsql/doc/src/sgml/array.sgml,v 1.8 2000/12/18 23:39:37 tgl Exp $
3+
-->
4+
15
<Chapter Id="arrays">
26
<Title>Arrays</Title>
37

@@ -30,7 +34,7 @@ CREATE TABLE sal_emp (
3034
(pay_by_quarter), which represents the employee's
3135
salary by quarter, and a two-dimensional array of <FirstTerm>text</FirstTerm>
3236
(schedule), which represents the employee's weekly
33-
schedule. Now we do some <FirstTerm>INSERTS</FirstTerm>s; note that when
37+
schedule. Now we do some <FirstTerm>INSERT</FirstTerm>s; note that when
3438
appending to an array, we enclose the values within
3539
braces and separate them by commas. If you know <FirstTerm>C</FirstTerm>,
3640
this is not unlike the syntax for initializing structures.
@@ -82,9 +86,10 @@ SELECT pay_by_quarter[3] FROM sal_emp;
8286
</Para>
8387

8488
<Para>
85-
We can also access arbitrary slices of an array, or
89+
We can also access arbitraryrectangularslices of an array, or
8690
subarrays. An array slice is denoted by writing
87-
"lower subscript : upper subscript" for one or more array
91+
<replaceable>lower subscript</replaceable> <literal>:</literal>
92+
<replaceable>upper subscript</replaceable> for one or more array
8893
dimensions. This query retrieves the first item on
8994
Bill's schedule for the first two days of the week:
9095

@@ -103,7 +108,11 @@ SELECT schedule[1:2][1:1] FROM sal_emp WHERE name = 'Bill';
103108
SELECT schedule[1:2][1] FROM sal_emp WHERE name = 'Bill';
104109
</ProgramListing>
105110

106-
with the same result.
111+
with the same result. An array subscripting operation is taken to
112+
represent an array slice if any of the subscripts are written in
113+
the form <replaceable>lower</replaceable> <literal>:</literal>
114+
<replaceable>upper</replaceable>. A lower bound of 1 is assumed
115+
for any subscript where only one value is specified.
107116
</Para>
108117

109118
<Para>
@@ -114,7 +123,7 @@ UPDATE sal_emp SET pay_by_quarter = '{25000,25000,27000,27000}'
114123
WHERE name = 'Carol';
115124
</ProgramListing>
116125

117-
or updated at a singleentry:
126+
or updated at a singleelement:
118127

119128
<ProgramListing>
120129
UPDATE sal_emp SET pay_by_quarter[4] = 15000
@@ -132,10 +141,11 @@ UPDATE sal_emp SET pay_by_quarter[1:2] = '{27000,27000}'
132141
<Para>
133142
An array can be enlarged by assigning to an element adjacent to
134143
those already present, or by assigning to a slice that is adjacent
135-
to or overlaps the data already present. Currently, this is only
136-
allowed for one-dimensional arrays, not multidimensional arrays.
144+
to or overlaps the data already present.
137145
For example, if an array value currently has 4 elements, it will
138146
have five elements after an update that assigns to array[5].
147+
Currently, enlargement in this fashion is only
148+
allowed for one-dimensional arrays, not multidimensional arrays.
139149
</Para>
140150

141151
<Para>
@@ -160,4 +170,22 @@ CREATE TABLE tictactoe (
160170
number of dimensions.
161171
</Para>
162172

173+
<Para>
174+
The current dimensions of any array value can be retrieved with
175+
the <function>array_dims</function> function:
176+
177+
<ProgramListing>
178+
SELECT array_dims(schedule) FROM sal_emp WHERE name = 'Carol';
179+
180+
array_dims
181+
------------
182+
[1:2][1:1]
183+
(1 row)
184+
</ProgramListing>
185+
186+
<function>array_dims</function> produces a <type>text</type> result,
187+
which is convenient for people to read but perhaps not so convenient
188+
for programs.
189+
</Para>
190+
163191
</Chapter>

‎doc/src/sgml/syntax.sgml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.28 2000/12/17 05:47:57 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.29 2000/12/18 23:39:37 tgl Exp $
33
-->
44

55
<chapter id="syntax">
@@ -555,12 +555,10 @@ CAST ( '<replaceable>string</replaceable>' AS <replaceable>type</replaceable> )
555555
</para>
556556

557557
<para>
558-
Individual array elements can be placed between single-quote
559-
marks to avoid ambiguity problems with respect to leading white space.
560-
Without quote marks, the array-value parser will skip white space.
561-
Note that to write a quote mark inside a string literal that is to
562-
become an array value, you must double the quote mark as described
563-
previously.
558+
Individual array elements can be placed between double-quote
559+
marks (<literal>"</literal>) to avoid ambiguity problems with respect to
560+
white space.
561+
Without quote marks, the array-value parser will skip leading white space.
564562
</para>
565563
</sect2>
566564
</sect1>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp