1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.86 2003/11/0409:55:39 petere Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.87 2003/11/0419:18:15 tgl Exp $
3
3
-->
4
4
5
5
<chapter id="sql-syntax">
@@ -185,7 +185,7 @@ UPDATE "my_table" SET "a" = 5;
185
185
186
186
<para>
187
187
Quoted identifiers can contain any character other than a double
188
- quote itself. To include a double quote, write two double quotes.
188
+ quote itself.( To include a double quote, write two double quotes.)
189
189
This allows constructing table or column names that would
190
190
otherwise not be possible, such as ones containing spaces or
191
191
ampersands. The length limitation still applies.
@@ -449,7 +449,7 @@ CAST ( '<replaceable>string</replaceable>' AS <replaceable>type</replaceable> )
449
449
</indexterm>
450
450
451
451
<para>
452
- An operator is a sequence of up to <symbol>NAMEDATALEN</symbol>-1
452
+ An operatorname is a sequence of up to <symbol>NAMEDATALEN</symbol>-1
453
453
(63 by default) characters from the following list:
454
454
<literallayout>
455
455
+ - * / < > = ~ ! @ # % ^ & | ` ?
@@ -855,6 +855,18 @@ SELECT 3 OPERATOR(pg_catalog.+) 4;
855
855
</para>
856
856
</listitem>
857
857
858
+ <listitem>
859
+ <para>
860
+ A subscripted expression.
861
+ </para>
862
+ </listitem>
863
+
864
+ <listitem>
865
+ <para>
866
+ A field selection expression.
867
+ </para>
868
+ </listitem>
869
+
858
870
<listitem>
859
871
<para>
860
872
An operator invocation.
@@ -928,31 +940,18 @@ SELECT 3 OPERATOR(pg_catalog.+) 4;
928
940
<synopsis>
929
941
<replaceable>correlation</replaceable>.<replaceable>columnname</replaceable>
930
942
</synopsis>
931
- or
932
- <synopsis>
933
- <replaceable>correlation</replaceable>.<replaceable>columnname</replaceable>[<replaceable>subscript</replaceable>]
934
- </synopsis>
935
- (Here, the brackets <literal>[ ]</literal> are meant to appear literally.)
936
943
</para>
937
944
938
945
<para>
939
946
<replaceable>correlation</replaceable> is the name of a
940
- table (possibly qualified), or an alias for a table defined by means of a
941
- <literal>FROM</literal> clause, or
947
+ table (possibly qualified with a schema name ), or an alias for a table
948
+ defined by means of a <literal>FROM</literal> clause, orone of
942
949
the key words <literal>NEW</literal> or <literal>OLD</literal>.
943
950
(<literal>NEW</literal> and <literal>OLD</literal> can only appear in rewrite rules,
944
951
while other correlation names can be used in any SQL statement.)
945
952
The correlation name and separating dot may be omitted if the column name
946
953
is unique across all the tables being used in the current query. (See also <xref linkend="queries">.)
947
954
</para>
948
-
949
- <para>
950
- If <replaceable>column</replaceable> is of an array type, then the
951
- optional <replaceable>subscript</replaceable> selects a specific
952
- element or elements in the array. If no subscript is provided, then the
953
- whole array is selected. (See <xref linkend="arrays"> for more about
954
- arrays.)
955
- </para>
956
955
</sect2>
957
956
958
957
<sect2>
@@ -995,6 +994,81 @@ CREATE FUNCTION dept(text) RETURNS dept
995
994
</para>
996
995
</sect2>
997
996
997
+ <sect2>
998
+ <title>Subscripts</title>
999
+
1000
+ <indexterm>
1001
+ <primary>subscript</primary>
1002
+ </indexterm>
1003
+
1004
+ <para>
1005
+ If an expression yields a value of an array type, then a specific
1006
+ element of the array value can be extracted by writing
1007
+ <synopsis>
1008
+ <replaceable>expression</replaceable>[<replaceable>subscript</replaceable>]
1009
+ </synopsis>
1010
+ or multiple adjacent elements (an <quote>array slice</>) can be extracted
1011
+ by writing
1012
+ <synopsis>
1013
+ <replaceable>expression</replaceable>[<replaceable>lower_subscript</replaceable>:<replaceable>upper_subscript</replaceable>]
1014
+ </synopsis>
1015
+ (Here, the brackets <literal>[ ]</literal> are meant to appear literally.)
1016
+ Each <replaceable>subscript</replaceable> is itself an expression,
1017
+ which must yield an integer value.
1018
+ </para>
1019
+
1020
+ <para>
1021
+ In general the array <replaceable>expression</replaceable> must be
1022
+ parenthesized, but the parentheses may be omitted when the expression
1023
+ to be subscripted is just a column reference or positional parameter.
1024
+ Also, multiple subscripts can be concatenated when the original array
1025
+ is multi-dimensional.
1026
+ For example,
1027
+
1028
+ <programlisting>
1029
+ mytable.arraycolumn[4]
1030
+ mytable.two_d_column[17][34]
1031
+ $1[10:42]
1032
+ (arrayfunction(a,b))[42]
1033
+ </programlisting>
1034
+
1035
+ The parentheses in the last example are required.
1036
+ See <xref linkend="arrays"> for more about arrays.
1037
+ </para>
1038
+ </sect2>
1039
+
1040
+ <sect2>
1041
+ <title>Field Selection</title>
1042
+
1043
+ <indexterm>
1044
+ <primary>field selection</primary>
1045
+ </indexterm>
1046
+
1047
+ <para>
1048
+ If an expression yields a value of a composite type (row type), then a
1049
+ specific field of the row can be extracted by writing
1050
+ <synopsis>
1051
+ <replaceable>expression</replaceable>.<replaceable>fieldname</replaceable>
1052
+ </synopsis>
1053
+ </para>
1054
+
1055
+ <para>
1056
+ In general the row <replaceable>expression</replaceable> must be
1057
+ parenthesized, but the parentheses may be omitted when the expression
1058
+ to be selected from is just a table reference or positional parameter.
1059
+ For example,
1060
+
1061
+ <programlisting>
1062
+ mytable.mycolumn
1063
+ $1.somecolumn
1064
+ (rowfunction(a,b)).col3
1065
+ </programlisting>
1066
+
1067
+ (Thus, a qualified column reference is actually just a special case
1068
+ of the field selection syntax.)
1069
+ </para>
1070
+ </sect2>
1071
+
998
1072
<sect2>
999
1073
<title>Operator Invocations</title>
1000
1074
@@ -1013,7 +1087,7 @@ CREATE FUNCTION dept(text) RETURNS dept
1013
1087
where the <replaceable>operator</replaceable> token follows the syntax
1014
1088
rules of <xref linkend="sql-syntax-operators">, or is one of the
1015
1089
key words <token>AND</token>, <token>OR</token>, and
1016
- <token>NOT</token>, or is a qualified operator name
1090
+ <token>NOT</token>, or is a qualified operator name in the form
1017
1091
<synopsis>
1018
1092
<literal>OPERATOR(</><replaceable>schema</><literal>.</><replaceable>operatorname</><literal>)</>
1019
1093
</synopsis>
@@ -1078,7 +1152,7 @@ sqrt(2)
1078
1152
</synopsis>
1079
1153
1080
1154
where <replaceable>aggregate_name</replaceable> is a previously
1081
- defined aggregate (possiblya qualified name), and
1155
+ defined aggregate (possiblyqualified with a schema name), and
1082
1156
<replaceable>expression</replaceable> is
1083
1157
any value expression that does not itself contain an aggregate
1084
1158
expression.