Skip to content

Commit 216e63b

Browse files
committed
Avoid mathematical inconsistency in example about avoiding division by
zero with a CASE expression. Per gripe from Russell Smith.
1 parent 8984c8b commit 216e63b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

doc/src/sgml/syntax.sgml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.120 2007/12/11 18:30:20 mha Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/syntax.sgml,v 1.121 2008/01/23 19:51:29 tgl Exp $ -->
22

33
<chapter id="sql-syntax">
44
<title>SQL Syntax</title>
@@ -1740,15 +1740,15 @@ SELECT somefunc() OR true;
17401740
used. For example, this is an untrustworthy way of trying to
17411741
avoid division by zero in a <literal>WHERE</> clause:
17421742
<programlisting>
1743-
SELECT ... WHERE x &lt;&gt; 0 AND y/x &gt; 1.5;
1743+
SELECT ... WHERE x &gt; 0 AND y/x &gt; 1.5;
17441744
</programlisting>
17451745
But this is safe:
17461746
<programlisting>
1747-
SELECT ... WHERE CASE WHEN x &lt;&gt; 0 THEN y/x &gt; 1.5 ELSE false END;
1747+
SELECT ... WHERE CASE WHEN x &gt; 0 THEN y/x &gt; 1.5 ELSE false END;
17481748
</programlisting>
17491749
A <literal>CASE</> construct used in this fashion will defeat optimization
17501750
attempts, so it should only be done when necessary. (In this particular
1751-
example, it would be best to sidestep the problem by writing
1751+
example, it would be better to sidestep the problem by writing
17521752
<literal>y &gt; 1.5*x</> instead.)
17531753
</para>
17541754
</sect2>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy