Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 08265ef

Browse files
committed
Fix example of syntactic ambiguity between prefix/infix/postfix operators
--- Postgres now accepts the example we claimed it wouldn't. Miscellaneous copy-editing as well.
1 parent 755a873 commit 08265ef

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

doc/src/sgml/syntax.sgml

Lines changed: 38 additions & 29 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.38 2001/01/26 22:04:22 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.39 2001/02/10 07:08:44 tgl Exp $
33
-->
44

55
<chapter id="sql-syntax">
@@ -49,7 +49,7 @@ INSERT INTO MY_TABLE VALUES (3, 'hi there');
4949
</programlisting>
5050
This is a sequence of three commands, one per line (although this
5151
is not required; more than one command can be on a line, and
52-
commands can be usefully split across lines).
52+
commands can usefully be split across lines).
5353
</para>
5454
</informalexample>
5555

@@ -115,7 +115,7 @@ UPDATE MY_TABLE SET A = 5;
115115
<programlisting>
116116
uPDaTE my_TabLE SeT a = 5;
117117
</programlisting>
118-
A good convention to adopt is perhaps to write key words in upper
118+
A convention often used is to write key words in upper
119119
case and names in lower case, e.g.,
120120
<programlisting>
121121
UPDATE my_table SET a = 5;
@@ -131,10 +131,10 @@ UPDATE my_table SET a = 5;
131131
identifier is always an identifier, never a key word. So
132132
<literal>"select"</literal> could be used to refer to a column or
133133
table named <quote>select</quote>, whereas an unquoted
134-
<literal>select</literal> would be taken as part of a command and
134+
<literal>select</literal> would be taken as a key word and
135135
would therefore provoke a parse error when used where a table or
136136
column name is expected. The example can be written with quoted
137-
identifiers like so:
137+
identifiers like this:
138138
<programlisting>
139139
UPDATE "my_table" SET "a" = 5;
140140
</programlisting>
@@ -157,11 +157,13 @@ UPDATE "my_table" SET "a" = 5;
157157
each other.
158158
<footnote>
159159
<para>
160-
This is incompatible with SQL, where unquoted names are folded to
161-
upper case. Thus, <literal>foo</literal> is equivalent to
162-
<literal>"FOO"</literal>. If you want to write portable
163-
applications you are advised to always quote a particular name or
164-
never quote it.
160+
<productname>Postgres</productname>' folding of unquoted names to lower
161+
case is incompatible with the SQL standard, which says that unquoted
162+
names should be folded to upper case. Thus, <literal>foo</literal>
163+
should be equivalent to <literal>"FOO"</literal> not
164+
<literal>"foo"</literal> according to the standard. If you want to
165+
write portable applications you are advised to always quote a particular
166+
name or never quote it.
165167
</para>
166168
</footnote>
167169
</para>
@@ -241,7 +243,7 @@ SELECT 'foo' 'bar';
241243
opening quote (no intervening whitespace), e.g.,
242244
<literal>B'1001'</literal>. The only characters allowed within
243245
bit string constants are <literal>0</literal> and
244-
<literal>1</literal>. Bit strings constants can be continued
246+
<literal>1</literal>. Bit string constants can be continued
245247
across lines in the same way as regular string constants.
246248
</para>
247249
</sect3>
@@ -271,7 +273,7 @@ SELECT 'foo' 'bar';
271273
</synopsis>
272274
where <replaceable>digits</replaceable> is one or more decimal
273275
digits. At least one digit must be before or after the decimal
274-
point and after the <literal>e</literal> if you use that option.
276+
point, and after the <literal>e</literal> if you use that option.
275277
Thus, a floating point constant is distinguished from an integer
276278
constant by the presence of either the decimal point or the
277279
exponent clause (or both). There must not be a space or other
@@ -486,8 +488,8 @@ CAST ( '<replaceable>string</replaceable>' AS <replaceable>type</replaceable> )
486488
<listitem>
487489
<para>
488490
The semicolon (<literal>;</literal>) terminates an SQL command.
489-
It cannot appear anywhere within a command, except when quoted
490-
as a string constant or identifier.
491+
It cannot appear anywhere within a command, except within a
492+
string constant or quoted identifier.
491493
</para>
492494
</listitem>
493495

@@ -648,7 +650,7 @@ CAST ( '<replaceable>string</replaceable>' AS <replaceable>type</replaceable> )
648650
<para>
649651
For further information on the system attributes consult
650652
<xref linkend="STON87a" endterm="STON87a">.
651-
Transaction and command identifiers are 32 bit quantities.
653+
Transaction and command identifiers are 32-bit quantities.
652654
</para>
653655

654656
</sect1>
@@ -658,7 +660,7 @@ CAST ( '<replaceable>string</replaceable>' AS <replaceable>type</replaceable> )
658660
<title>Value Expressions</title>
659661

660662
<para>
661-
Value expressions are used in a variety of syntactic contexts, such
663+
Value expressions are used in a variety of contexts, such
662664
as in the target list of the <command>SELECT</command> command, as
663665
new column values in <command>INSERT</command> or
664666
<command>UPDATE</command>, or in search conditions in a number of
@@ -692,13 +694,13 @@ CAST ( '<replaceable>string</replaceable>' AS <replaceable>type</replaceable> )
692694
An operator invocation:
693695
<simplelist>
694696
<member><replaceable>expression</replaceable> <replaceable>operator</replaceable> <replaceable>expression</replaceable> (binary infix operator)</member>
695-
<member><replaceable>expression</replaceable> <replaceable>operator</replaceable> (unary postfix operator)</member>
696697
<member><replaceable>operator</replaceable> <replaceable>expression</replaceable> (unary prefix operator)</member>
698+
<member><replaceable>expression</replaceable> <replaceable>operator</replaceable> (unary postfix operator)</member>
697699
</simplelist>
698700
where <replaceable>operator</replaceable> follows the syntax
699701
rules of <xref linkend="sql-syntax-operators"> or is one of the
700702
tokens <token>AND</token>, <token>OR</token>, and
701-
<token>NOT</token>. What particular operators exist and whether
703+
<token>NOT</token>. Which particular operators exist and whether
702704
they are unary or binary depends on what operators have been
703705
defined by the system or the user. <xref linkend="functions">
704706
describes the built-in operators.
@@ -733,7 +735,7 @@ CAST ( '<replaceable>string</replaceable>' AS <replaceable>type</replaceable> )
733735
<listitem>
734736
<para>
735737
A scalar subquery. This is an ordinary
736-
<command>SELECT</command> in parenthesis that returns exactly one
738+
<command>SELECT</command> in parentheses that returns exactly one
737739
row with one column. It is an error to use a subquery that
738740
returns more than one row or more than one column in the context
739741
of a value expression.
@@ -813,9 +815,9 @@ CREATE FUNCTION dept (text) RETURNS dept
813815
<title>Function Calls</title>
814816

815817
<para>
816-
The syntax for a function call is the name of a legal function
817-
(subject to the syntax rules for identifiers of <xref
818-
linkend="sql-syntax-identifiers"> , followed by its argument list
818+
The syntax for a function call is the name of a function
819+
(which is subject to the syntax rules for identifiers of <xref
820+
linkend="sql-syntax-identifiers">), followed by its argument list
819821
enclosed in parentheses:
820822

821823
<synopsis>
@@ -862,7 +864,9 @@ sqrt(2)
862864
<para>
863865
The first form of aggregate expression invokes the aggregate
864866
across all input rows for which the given expression yields a
865-
non-NULL value. The second form is the same as the first, since
867+
non-NULL value. (Actually, it is up to the aggregate function
868+
whether to ignore NULLs or not --- but all the standard ones do.)
869+
The second form is the same as the first, since
866870
<literal>ALL</literal> is the default. The third form invokes the
867871
aggregate for all distinct non-NULL values of the expression found
868872
in the input rows. The last form invokes the aggregate once for
@@ -881,7 +885,8 @@ sqrt(2)
881885

882886
<para>
883887
The predefined aggregate functions are described in <xref
884-
linkend="functions-aggregate">.
888+
linkend="functions-aggregate">. Other aggregate functions may be added
889+
by the user.
885890
</para>
886891
</sect2>
887892

@@ -900,15 +905,19 @@ sqrt(2)
900905
you will sometimes need to add parentheses when using combinations
901906
of binary and unary operators. For instance
902907
<programlisting>
903-
SELECT 5 &amp; ~ 6;
908+
SELECT 5 ! ~ 6;
904909
</programlisting>
905910
will be parsed as
906911
<programlisting>
907-
SELECT (5 &amp;) ~ 6;
912+
SELECT 5 ! (~ 6);
913+
</programlisting>
914+
because the parser has no idea --- until it's too late --- that
915+
<token>!</token> is defined as a postfix operator not an infix one.
916+
To get the desired behavior in this case, you must write
917+
<programlisting>
918+
SELECT (5 !) ~ 6;
908919
</programlisting>
909-
because the parser has no idea that <token>&amp;</token> is
910-
defined as a binary operator. This is the price one pays for
911-
extensibility.
920+
This is the price one pays for extensibility.
912921
</para>
913922

914923
<table tocentry="1">

0 commit comments

Comments
 (0)