Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
2da3742c
Commit
2da3742c
authored
Jun 15, 2002
by
Tom Lane
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a little more material to the new section about evaluation order.
parent
eb1ad5b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
6 deletions
+25
-6
doc/src/sgml/syntax.sgml
doc/src/sgml/syntax.sgml
+25
-6
No files found.
doc/src/sgml/syntax.sgml
View file @
2da3742c
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.6
1 2002/06/01 20:56:55 petere
Exp $
$Header: /cvsroot/pgsql/doc/src/sgml/syntax.sgml,v 1.6
2 2002/06/15 21:28:55 tgl
Exp $
-->
<chapter id="sql-syntax">
...
...
@@ -1435,14 +1435,13 @@ FROM states;
<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.
particular, the inputs of an operator or function are not necessarily
evaluated left-to-right or in any other fixed order.
</para>
<para>
Furthermore, if the result of an expression can be determined by
evaluating only some parts of it, then
some
subexpressions
evaluating only some parts of it, then
other
subexpressions
might not be evaluated at all. For instance, if one wrote
<programlisting>
SELECT true OR somefunc();
...
...
@@ -1459,7 +1458,27 @@ SELECT somefunc() OR true;
<para>
As a consequence, it is unwise to use functions with side effects
as part of complex expressions.
as part of complex expressions. It is particularly dangerous to
rely on side effects or evaluation order in WHERE and HAVING clauses,
since those clauses are extensively reprocessed as part of
developing an execution plan. Boolean
expressions (AND/OR/NOT combinations) in those clauses may be reorganized
in any manner allowed by the laws of Boolean algebra.
</para>
<para>
When it is essential to force evaluation order, a CASE construct may
be used. For example, this is an untrustworthy way of trying to
avoid division by zero in a WHERE clause:
<programlisting>
SELECT ... WHERE x <> 0 AND y/x > 1.5;
</programlisting>
but this is safe:
<programlisting>
SELECT ... WHERE CASE WHEN x <> 0 THEN y/x > 1.5 ELSE false END;
</programlisting>
A CASE construct used in this fashion will defeat optimization attempts,
so it should only be done when necessary.
</para>
</sect2>
</sect1>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment