From 08265ef9c2aede6f3d0161c6c15a3d0d87a79b88 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 10 Feb 2001 07:08:44 +0000 Subject: [PATCH] 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. --- doc/src/sgml/syntax.sgml | 67 +++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml index dd7702cbf0..cd463488fb 100644 --- a/doc/src/sgml/syntax.sgml +++ b/doc/src/sgml/syntax.sgml @@ -1,5 +1,5 @@ @@ -49,7 +49,7 @@ INSERT INTO MY_TABLE VALUES (3, 'hi there'); This is a sequence of three commands, one per line (although this is not required; more than one command can be on a line, and - commands can be usefully split across lines). + commands can usefully be split across lines). @@ -115,7 +115,7 @@ UPDATE MY_TABLE SET A = 5; uPDaTE my_TabLE SeT a = 5; - A good convention to adopt is perhaps to write key words in upper + A convention often used is to write key words in upper case and names in lower case, e.g., UPDATE my_table SET a = 5; @@ -131,10 +131,10 @@ UPDATE my_table SET a = 5; identifier is always an identifier, never a key word. So "select" could be used to refer to a column or table named select, whereas an unquoted - select would be taken as part of a command and + select would be taken as a key word and would therefore provoke a parse error when used where a table or column name is expected. The example can be written with quoted - identifiers like so: + identifiers like this: UPDATE "my_table" SET "a" = 5; @@ -157,11 +157,13 @@ UPDATE "my_table" SET "a" = 5; each other. - This is incompatible with SQL, where unquoted names are folded to - upper case. Thus, foo is equivalent to - "FOO". If you want to write portable - applications you are advised to always quote a particular name or - never quote it. + Postgres' folding of unquoted names to lower + case is incompatible with the SQL standard, which says that unquoted + names should be folded to upper case. Thus, foo + should be equivalent to "FOO" not + "foo" according to the standard. If you want to + write portable applications you are advised to always quote a particular + name or never quote it. @@ -241,7 +243,7 @@ SELECT 'foo' 'bar'; opening quote (no intervening whitespace), e.g., B'1001'. The only characters allowed within bit string constants are 0 and - 1. Bit strings constants can be continued + 1. Bit string constants can be continued across lines in the same way as regular string constants. @@ -271,7 +273,7 @@ SELECT 'foo' 'bar'; where digits is one or more decimal digits. At least one digit must be before or after the decimal - point and after the e if you use that option. + point, and after the e if you use that option. Thus, a floating point constant is distinguished from an integer constant by the presence of either the decimal point or the exponent clause (or both). There must not be a space or other @@ -486,8 +488,8 @@ CAST ( 'string' AS type ) The semicolon (;) terminates an SQL command. - It cannot appear anywhere within a command, except when quoted - as a string constant or identifier. + It cannot appear anywhere within a command, except within a + string constant or quoted identifier. @@ -648,7 +650,7 @@ CAST ( 'string' AS type ) For further information on the system attributes consult . - Transaction and command identifiers are 32 bit quantities. + Transaction and command identifiers are 32-bit quantities. @@ -658,7 +660,7 @@ CAST ( 'string' AS type ) Value Expressions - Value expressions are used in a variety of syntactic contexts, such + Value expressions are used in a variety of contexts, such as in the target list of the SELECT command, as new column values in INSERT or UPDATE, or in search conditions in a number of @@ -692,13 +694,13 @@ CAST ( 'string' AS type ) An operator invocation: expression operator expression (binary infix operator) - expression operator (unary postfix operator) operator expression (unary prefix operator) + expression operator (unary postfix operator) where operator follows the syntax rules of or is one of the tokens AND, OR, and - NOT. What particular operators exist and whether + NOT. Which particular operators exist and whether they are unary or binary depends on what operators have been defined by the system or the user. describes the built-in operators. @@ -733,7 +735,7 @@ CAST ( 'string' AS type ) A scalar subquery. This is an ordinary - SELECT in parenthesis that returns exactly one + SELECT in parentheses that returns exactly one row with one column. It is an error to use a subquery that returns more than one row or more than one column in the context of a value expression. @@ -813,9 +815,9 @@ CREATE FUNCTION dept (text) RETURNS dept Function Calls - The syntax for a function call is the name of a legal function - (subject to the syntax rules for identifiers of , followed by its argument list + The syntax for a function call is the name of a function + (which is subject to the syntax rules for identifiers of ), followed by its argument list enclosed in parentheses: @@ -862,7 +864,9 @@ sqrt(2) The first form of aggregate expression invokes the aggregate across all input rows for which the given expression yields a - non-NULL value. The second form is the same as the first, since + non-NULL value. (Actually, it is up to the aggregate function + whether to ignore NULLs or not --- but all the standard ones do.) + The second form is the same as the first, since ALL is the default. The third form invokes the aggregate for all distinct non-NULL values of the expression found in the input rows. The last form invokes the aggregate once for @@ -881,7 +885,8 @@ sqrt(2) The predefined aggregate functions are described in . + linkend="functions-aggregate">. Other aggregate functions may be added + by the user. @@ -900,15 +905,19 @@ sqrt(2) you will sometimes need to add parentheses when using combinations of binary and unary operators. For instance -SELECT 5 & ~ 6; +SELECT 5 ! ~ 6; will be parsed as -SELECT (5 &) ~ 6; +SELECT 5 ! (~ 6); + + because the parser has no idea --- until it's too late --- that + ! is defined as a postfix operator not an infix one. + To get the desired behavior in this case, you must write + +SELECT (5 !) ~ 6; - because the parser has no idea that & is - defined as a binary operator. This is the price one pays for - extensibility. + This is the price one pays for extensibility. -- 2.11.0