From: Tom Lane Date: Wed, 23 Jan 2008 19:51:29 +0000 (+0000) Subject: Avoid mathematical inconsistency in example about avoiding division by X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=c704a6abcdf1b584d01623775baa46110e0214a8;p=users%2Fbernd%2Fpostgres.git Avoid mathematical inconsistency in example about avoiding division by zero with a CASE expression. Per gripe from Russell Smith. --- diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml index 7ec0e859b5..70fe502854 100644 --- a/doc/src/sgml/syntax.sgml +++ b/doc/src/sgml/syntax.sgml @@ -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.)