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).
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;
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;
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.
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.
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
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.
For further information on the system attributes consult
.
- Transaction and command identifiers are 32 bit quantities.
+ Transaction and command identifiers are 32-bit quantities.
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
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.
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.
Function Calls
- The syntax for a function call is the name of a legal function
- (subject to the syntax rules for identifiers of
- linkend="sql-syntax-identifiers"> , 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
+ linkend="sql-syntax-identifiers">), followed by its argument list
enclosed in parentheses:
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
The predefined aggregate functions are described in
- linkend="functions-aggregate">.
+ linkend="functions-aggregate">. Other aggregate functions may be added
+ by the user.
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.