Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
bf886d5b
Commit
bf886d5b
authored
23 years ago
by
Peter Eisentraut
Browse files
Options
Downloads
Patches
Plain Diff
Add section explaining unspecified expression evaluation order.
parent
1731048c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/src/sgml/syntax.sgml
+210
-183
210 additions, 183 deletions
doc/src/sgml/syntax.sgml
with
210 additions
and
183 deletions
doc/src/sgml/syntax.sgml
+
210
−
183
View file @
bf886d5b
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.6
0
2002/0
4/25 20:14:43 tgl
Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.6
1
2002/0
6/01 20:56:55 petere
Exp $
-->
<chapter id="sql-syntax">
...
...
@@ -44,7 +44,6 @@ $Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.60 2002/04/25 20:14:43 tgl
whitespace.
</para>
<informalexample id="sql-syntax-ex-commands">
<para>
For example, the following is (syntactically) valid SQL input:
<programlisting>
...
...
@@ -56,7 +55,6 @@ INSERT INTO MY_TABLE VALUES (3, 'hi there');
is not required; more than one command can be on a line, and
commands can usefully be split across lines).
</para>
</informalexample>
<para>
The SQL syntax is not very consistent regarding what tokens
...
...
@@ -328,7 +326,6 @@ SELECT 'foo' 'bar';
characters embedded in the constant.
</para>
<informalexample>
<para>
These are some examples of valid floating-point constants:
<literallayout>
...
...
@@ -339,7 +336,6 @@ SELECT 'foo' 'bar';
1.925e-3
</literallayout>
</para>
</informalexample>
<para>
Floating-point constants are of type <type>DOUBLE
...
...
@@ -621,6 +617,184 @@ CAST ( '<replaceable>string</replaceable>' AS <replaceable>type</replaceable> )
analysis and is effectively replaced by whitespace.
</para>
</sect2>
<sect2 id="sql-precedence">
<title>Lexical Precedence</title>
<indexterm zone="sql-precedence">
<primary>operators</primary>
<secondary>precedence</secondary>
</indexterm>
<para>
The precedence and associativity of the operators is hard-wired
into the parser. Most operators have the same precedence and are
left-associative. This may lead to non-intuitive behavior; for
example the Boolean operators <literal><</> and <literal>></> have a different
precedence than the Boolean operators <literal><=</> and <literal>>=</>. Also,
you will sometimes need to add parentheses when using combinations
of binary and unary operators. For instance
<programlisting>
SELECT 5 ! - 6;
</programlisting>
will be parsed as
<programlisting>
SELECT 5 ! (- 6);
</programlisting>
because the parser has no idea -- until it is too late -- that
<token>!</token> is defined as a postfix operator, not an infix one.
To get the desired behavior in this case, you must write
<programlisting>
SELECT (5 !) - 6;
</programlisting>
This is the price one pays for extensibility.
</para>
<table tocentry="1">
<title>Operator Precedence (decreasing)</title>
<tgroup cols="3">
<thead>
<row>
<entry>Operator/Element</entry>
<entry>Associativity</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><token>.</token></entry>
<entry>left</entry>
<entry>table/column name separator</entry>
</row>
<row>
<entry><token>::</token></entry>
<entry>left</entry>
<entry><productname>PostgreSQL</productname>-style typecast</entry>
</row>
<row>
<entry><token>[</token> <token>]</token></entry>
<entry>left</entry>
<entry>array element selection</entry>
</row>
<row>
<entry><token>-</token></entry>
<entry>right</entry>
<entry>unary minus</entry>
</row>
<row>
<entry><token>^</token></entry>
<entry>left</entry>
<entry>exponentiation</entry>
</row>
<row>
<entry><token>*</token> <token>/</token> <token>%</token></entry>
<entry>left</entry>
<entry>multiplication, division, modulo</entry>
</row>
<row>
<entry><token>+</token> <token>-</token></entry>
<entry>left</entry>
<entry>addition, subtraction</entry>
</row>
<row>
<entry><token>IS</token></entry>
<entry></entry>
<entry>test for TRUE, FALSE, UNKNOWN, NULL</entry>
</row>
<row>
<entry><token>ISNULL</token></entry>
<entry></entry>
<entry>test for NULL</entry>
</row>
<row>
<entry><token>NOTNULL</token></entry>
<entry></entry>
<entry>test for NOT NULL</entry>
</row>
<row>
<entry>(any other)</entry>
<entry>left</entry>
<entry>all other native and user-defined operators</entry>
</row>
<row>
<entry><token>IN</token></entry>
<entry></entry>
<entry>set membership</entry>
</row>
<row>
<entry><token>BETWEEN</token></entry>
<entry></entry>
<entry>containment</entry>
</row>
<row>
<entry><token>OVERLAPS</token></entry>
<entry></entry>
<entry>time interval overlap</entry>
</row>
<row>
<entry><token>LIKE</token> <token>ILIKE</token></entry>
<entry></entry>
<entry>string pattern matching</entry>
</row>
<row>
<entry><token><</token> <token>></token></entry>
<entry></entry>
<entry>less than, greater than</entry>
</row>
<row>
<entry><token>=</token></entry>
<entry>right</entry>
<entry>equality, assignment</entry>
</row>
<row>
<entry><token>NOT</token></entry>
<entry>right</entry>
<entry>logical negation</entry>
</row>
<row>
<entry><token>AND</token></entry>
<entry>left</entry>
<entry>logical conjunction</entry>
</row>
<row>
<entry><token>OR</token></entry>
<entry>left</entry>
<entry>logical disjunction</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
Note that the operator precedence rules also apply to user-defined
operators that have the same names as the built-in operators
mentioned above. For example, if you define a
<quote>+</quote> operator for some custom data type it will have
the same precedence as the built-in <quote>+</quote> operator, no
matter what yours does.
</para>
</sect2>
</sect1>
<sect1 id="sql-naming">
...
...
@@ -1256,185 +1430,38 @@ FROM states;
</para>
</sect2>
</sect1>
<sect1 id="sql-precedence">
<title>Lexical Precedence</title>
<sect2>
<title>Expression Evaluation</title>
<indexterm zone="sql-precedence">
<primary>operators</primary>
<secondary>precedence</secondary>
</indexterm>
<para>
The order of evaluation of subexpressions is not defined. In
particular, subexpressions are not necessarily evaluated
left-to-right, right-to-left, or according to the lexical
precedence rules.
</para>
<para>
The precedence and associativity of the operators is hard-wired
into the parser. Most operators have the same precedence and are
left-associative. This may lead to non-intuitive behavior; for
example the Boolean operators <literal><</> and <literal>></> have a different
precedence than the Boolean operators <literal><=</> and <literal>>=</>. Also,
you will sometimes need to add parentheses when using combinations
of binary and unary operators. For instance
<programlisting>
SELECT 5 ! - 6;
</programlisting>
will be parsed as
Furthermore, if the result of an expression can be determined by
evaluating only some parts of it, then some subexpressions
might not be evaluated at all. For instance, if one wrote
<programlisting>
SELECT
5 ! (- 6
);
SELECT
true OR somefunc(
);
</programlisting>
because the parser has no idea -- until it is too late -- that
<token>!</token> is defined as a postfix operator, not an infix one.
To get the desired behavior in this case, you must write
then <literal>somefunc()</literal> would (probably) not be called
at all. The same would be the case if one wrote
<programlisting>
SELECT
(5 !) - 6
;
SELECT
somefunc() OR true
;
</programlisting>
This is the price one pays for extensibility.
Note that this is not the same as the left-to-right
<quote>short-circuiting</quote> of Boolean operators that is found
in some programming languages.
</para>
<table tocentry="1">
<title>Operator Precedence (decreasing)</title>
<tgroup cols="3">
<thead>
<row>
<entry>Operator/Element</entry>
<entry>Associativity</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><token>.</token></entry>
<entry>left</entry>
<entry>table/column name separator</entry>
</row>
<row>
<entry><token>::</token></entry>
<entry>left</entry>
<entry><productname>PostgreSQL</productname>-style typecast</entry>
</row>
<row>
<entry><token>[</token> <token>]</token></entry>
<entry>left</entry>
<entry>array element selection</entry>
</row>
<row>
<entry><token>-</token></entry>
<entry>right</entry>
<entry>unary minus</entry>
</row>
<row>
<entry><token>^</token></entry>
<entry>left</entry>
<entry>exponentiation</entry>
</row>
<row>
<entry><token>*</token> <token>/</token> <token>%</token></entry>
<entry>left</entry>
<entry>multiplication, division, modulo</entry>
</row>
<row>
<entry><token>+</token> <token>-</token></entry>
<entry>left</entry>
<entry>addition, subtraction</entry>
</row>
<row>
<entry><token>IS</token></entry>
<entry></entry>
<entry>test for TRUE, FALSE, UNKNOWN, NULL</entry>
</row>
<row>
<entry><token>ISNULL</token></entry>
<entry></entry>
<entry>test for NULL</entry>
</row>
<row>
<entry><token>NOTNULL</token></entry>
<entry></entry>
<entry>test for NOT NULL</entry>
</row>
<row>
<entry>(any other)</entry>
<entry>left</entry>
<entry>all other native and user-defined operators</entry>
</row>
<row>
<entry><token>IN</token></entry>
<entry></entry>
<entry>set membership</entry>
</row>
<row>
<entry><token>BETWEEN</token></entry>
<entry></entry>
<entry>containment</entry>
</row>
<row>
<entry><token>OVERLAPS</token></entry>
<entry></entry>
<entry>time interval overlap</entry>
</row>
<row>
<entry><token>LIKE</token> <token>ILIKE</token></entry>
<entry></entry>
<entry>string pattern matching</entry>
</row>
<row>
<entry><token><</token> <token>></token></entry>
<entry></entry>
<entry>less than, greater than</entry>
</row>
<row>
<entry><token>=</token></entry>
<entry>right</entry>
<entry>equality, assignment</entry>
</row>
<row>
<entry><token>NOT</token></entry>
<entry>right</entry>
<entry>logical negation</entry>
</row>
<row>
<entry><token>AND</token></entry>
<entry>left</entry>
<entry>logical conjunction</entry>
</row>
<row>
<entry><token>OR</token></entry>
<entry>left</entry>
<entry>logical disjunction</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
Note that the operator precedence rules also apply to user-defined
operators that have the same names as the built-in operators
mentioned above. For example, if you define a
<quote>+</quote> operator for some custom data type it will have
the same precedence as the built-in <quote>+</quote> operator, no
matter what yours does.
As a consequence, it is unwise to use functions with side effects
as part of complex expressions.
</para>
</sect2>
</sect1>
</chapter>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment