From 216e63bbce59aba7ab8e0f96219c7ec0a120207d Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 23 Jan 2008 19:51:29 +0000 Subject: [PATCH] Avoid mathematical inconsistency in example about avoiding division by zero with a CASE expression. Per gripe from Russell Smith. --- doc/src/sgml/syntax.sgml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml index c49d81b7f9..8761b6e1da 100644 --- a/doc/src/sgml/syntax.sgml +++ b/doc/src/sgml/syntax.sgml @@ -1,4 +1,4 @@ - + SQL Syntax @@ -1740,15 +1740,15 @@ SELECT somefunc() OR true; used. For example, this is an untrustworthy way of trying to avoid division by zero in a WHERE clause: -SELECT ... WHERE x <> 0 AND y/x > 1.5; +SELECT ... WHERE x > 0 AND y/x > 1.5; But this is safe: -SELECT ... WHERE CASE WHEN x <> 0 THEN y/x > 1.5 ELSE false END; +SELECT ... WHERE CASE WHEN x > 0 THEN y/x > 1.5 ELSE false END; A CASE construct used in this fashion will defeat optimization attempts, so it should only be done when necessary. (In this particular - example, it would be best to sidestep the problem by writing + example, it would be better to sidestep the problem by writing y > 1.5*x instead.) -- GitLab