Re: Minor mathematical error in documentation - Mailing list pgsql-bugs

From Peter Eisentraut
Subject Re: Minor mathematical error in documentation
Date
Msg-id 200801172056.02664.peter_e@gmx.net
Whole thread Raw
In response to Minor mathematical error in documentation  (Russell Smith <mr-russ@pws.com.au>)
List pgsql-bugs
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/

pgsql-bugs by date:

Previous
From: "Steven Flatt"
Date:
Subject: Re: BUG #3883: Autovacuum deadlock with truncate?
Next
From: Tom Lane
Date:
Subject: Re: BUG #3882: unexpected PARAM_SUBLINK ID