Russell Smith wrote:
> 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 y > 1.5*x instead.)
>
>
> In-equality transformations do not guarantee that y > 1.5x == y/x >
> 1.5. This is only true for x>0
So the proper expression would be
SELECT ... WHERE CASE WHEN x >= 0 THEN y > 1.5*x ELSE y < 1.5*x END;
or
SELECT ... WHERE (x >= 0 AND y > 1.5*x) OR y < 1.5*x;
which obviously isn't simpler. So I suggest that we just delete the
parenthetical note.
--
Peter Eisentraut
http://developer.postgresql.org/~petere/