-
+
SQL Syntax
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.)