Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
8a25ec84
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8a25ec84
编写于
3月 17, 2002
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve documentation about array I/O representation.
上级
0f2fbbba
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
13 deletion
+58
-13
doc/src/sgml/array.sgml
doc/src/sgml/array.sgml
+58
-13
未找到文件。
doc/src/sgml/array.sgml
浏览文件 @
8a25ec84
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/array.sgml,v 1.
19 2002/01/20 22:19:55 petere
Exp $ -->
<!-- $Header: /cvsroot/pgsql/doc/src/sgml/array.sgml,v 1.
20 2002/03/17 19:59:57 tgl
Exp $ -->
<chapter id="arrays">
<chapter id="arrays">
<title>Arrays</title>
<title>Arrays</title>
...
@@ -22,8 +22,9 @@ CREATE TABLE sal_emp (
...
@@ -22,8 +22,9 @@ CREATE TABLE sal_emp (
As shown, an array data type is named by appending square brackets
As shown, an array data type is named by appending square brackets
(<literal>[]</>) to the data type name of the array elements.
(<literal>[]</>) to the data type name of the array elements.
The above query will create a table named
The above query will create a table named
<structname>sal_emp</structname> with a <type>text</type> string
<structname>sal_emp</structname> with columns including
(<structfield>name</structfield>), a one-dimensional array of type
a <type>text</type> string (<structfield>name</structfield>),
a one-dimensional array of type
<type>integer</type> (<structfield>pay_by_quarter</structfield>),
<type>integer</type> (<structfield>pay_by_quarter</structfield>),
which represents the employee's salary by quarter, and a
which represents the employee's salary by quarter, and a
two-dimensional array of <type>text</type>
two-dimensional array of <type>text</type>
...
@@ -35,7 +36,7 @@ CREATE TABLE sal_emp (
...
@@ -35,7 +36,7 @@ CREATE TABLE sal_emp (
Now we do some <command>INSERT</command>s. Observe that to write an array
Now we do some <command>INSERT</command>s. Observe that to write an array
value, we enclose the element values within curly braces and separate them
value, we enclose the element values within curly braces and separate them
by commas. If you know C, this is not unlike the syntax for
by commas. If you know C, this is not unlike the syntax for
initializing structures.
initializing structures.
(More details appear below.)
<programlisting>
<programlisting>
INSERT INTO sal_emp
INSERT INTO sal_emp
...
@@ -66,7 +67,7 @@ SELECT name FROM sal_emp WHERE pay_by_quarter[1] <> pay_by_quarter[2];
...
@@ -66,7 +67,7 @@ SELECT name FROM sal_emp WHERE pay_by_quarter[1] <> pay_by_quarter[2];
</programlisting>
</programlisting>
The array subscript numbers are written within square brackets.
The array subscript numbers are written within square brackets.
<productname>PostgreSQL</productname> uses the
By default
<productname>PostgreSQL</productname> uses the
<quote>one-based</quote> numbering convention for arrays, that is,
<quote>one-based</quote> numbering convention for arrays, that is,
an array of <replaceable>n</> elements starts with <literal>array[1]</literal> and
an array of <replaceable>n</> elements starts with <literal>array[1]</literal> and
ends with <literal>array[<replaceable>n</>]</literal>.
ends with <literal>array[<replaceable>n</>]</literal>.
...
@@ -99,7 +100,7 @@ SELECT schedule[1:2][1:1] FROM sal_emp WHERE name = 'Bill';
...
@@ -99,7 +100,7 @@ SELECT schedule[1:2][1:1] FROM sal_emp WHERE name = 'Bill';
schedule
schedule
--------------------
--------------------
{{
"meeting"
},{""}}
{{
meeting
},{""}}
(1 row)
(1 row)
</programlisting>
</programlisting>
...
@@ -144,11 +145,17 @@ UPDATE sal_emp SET pay_by_quarter[1:2] = '{27000,27000}'
...
@@ -144,11 +145,17 @@ UPDATE sal_emp SET pay_by_quarter[1:2] = '{27000,27000}'
those already present, or by assigning to a slice that is adjacent
those already present, or by assigning to a slice that is adjacent
to or overlaps the data already present. For example, if an array
to or overlaps the data already present. For example, if an array
value currently has 4 elements, it will have five elements after an
value currently has 4 elements, it will have five elements after an
update that assigns to
array[5]. Currently, enlargement in this
update that assigns to
<literal>array[5]</>. Currently, enlargement in
fashion is only allowed for one-dimensional arrays, not
this
fashion is only allowed for one-dimensional arrays, not
multidimensional arrays.
multidimensional arrays.
</para>
</para>
<para>
Array slice assignment allows creation of arrays that do not use one-based
subscripts. For example one might assign to <literal>array[-2:7]</> to
create an array with subscript values running from -2 to 7.
</para>
<para>
<para>
The syntax for <command>CREATE TABLE</command> allows fixed-length
The syntax for <command>CREATE TABLE</command> allows fixed-length
arrays to be defined:
arrays to be defined:
...
@@ -168,7 +175,9 @@ CREATE TABLE tictactoe (
...
@@ -168,7 +175,9 @@ CREATE TABLE tictactoe (
Actually, the current implementation does not enforce the declared
Actually, the current implementation does not enforce the declared
number of dimensions either. Arrays of a particular element type are
number of dimensions either. Arrays of a particular element type are
all considered to be of the same type, regardless of size or number
all considered to be of the same type, regardless of size or number
of dimensions.
of dimensions. So, declaring number of dimensions or sizes in
<command>CREATE TABLE</command> is simply documentation, it does not
affect runtime behavior.
</para>
</para>
<para>
<para>
...
@@ -248,19 +257,55 @@ SELECT * FROM sal_emp WHERE pay_by_quarter **= 10000;
...
@@ -248,19 +257,55 @@ SELECT * FROM sal_emp WHERE pay_by_quarter **= 10000;
</para>
</para>
</note>
</note>
<formalpara>
<title>Array input and output syntax.</title>
<para>
The external representation of an array value consists of items that
are interpreted according to the I/O conversion rules for the array's
element type, plus decoration that indicates the array structure.
The decoration consists of curly braces (<literal>{</> and <literal>}</>)
around the array value plus delimiter characters between adjacent items.
The delimiter character is usually a comma (<literal>,</>) but can be
something else: it is determined by the <literal>typdelim</> setting
for the array's element type. (Among the standard datatypes provided
in the <productname>PostgreSQL</productname> distribution, type
<literal>box</> uses a semicolon (<literal>;</>) but all the others
use comma.) In a multidimensional array, each dimension (row, plane,
cube, etc.) gets its own level of curly braces, and delimiters
must be written between adjacent curly-braced entities of the same level.
You may write whitespace before a left brace, after a right
brace, or before any individual item string. Whitespace after an item
is not ignored, however: after skipping leading whitespace, everything
up to the next right brace or delimiter is taken as the item value.
</para>
</formalpara>
<formalpara>
<formalpara>
<title>Quoting array elements.</title>
<title>Quoting array elements.</title>
<para>
<para>
As shown above, when writing an array
literal
value you may write double
As shown above, when writing an array value you may write double
quotes around any individual array
quotes around any individual array
element. You <emphasis>must</> do so if the element value would otherwise
element. You <emphasis>must</> do so if the element value would otherwise
confuse the array-value parser. For example, elements containing curly
confuse the array-value parser. For example, elements containing curly
braces, commas, double quotes, backslashes, or white space must be
braces, commas (or whatever the delimiter character is), double quotes,
double-quoted. To put a double quote or backslash in an array element
backslashes, or leading white space must be double-quoted. To put a double
value, precede it with a backslash.
quote or backslash in an array element value, precede it with a backslash.
Alternatively, you can use backslash-escaping to protect all data characters
that would otherwise be taken as array syntax or ignorable white space.
</para>
</para>
</formalpara>
</formalpara>
<para>
The array output routine will put double quotes around element values
if they are empty strings or contain curly braces, delimiter characters,
double quotes, backslashes, or white space. Double quotes and backslashes
embedded in element values will be backslash-escaped. For numeric
datatypes it is safe to assume that double quotes will never appear, but
for textual datatypes one should be prepared to cope with either presence
or absence of quotes. (This is a change in behavior from pre-7.2
<productname>PostgreSQL</productname> releases.)
</para>
<tip>
<tip>
<para>
<para>
Remember that what you write in an SQL query will first be interpreted
Remember that what you write in an SQL query will first be interpreted
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录