Re: wierd AND condition evaluation for plpgsql - Mailing list pgsql-hackers

From Tom Lane
Subject Re: wierd AND condition evaluation for plpgsql
Date
Msg-id 1415.1022775249@sss.pgh.pa.us
Whole thread Raw
In response to Re: wierd AND condition evaluation for plpgsql  ("Joel Burton" <joel@joelburton.com>)
List pgsql-hackers
"Joel Burton" <joel@joelburton.com> writes:
> Is there any generalizable help would could offer to people who write
> functions that have side effects? Don't use them in WHERE (or ON or HAVING)
> clauses? Evaluate the function in a earlier db call, then plug the resolved
> results into the SQL WHERE statement?

Certainly putting side-effects into WHERE clauses is a recipe for
trouble, and it'd not be a bad idea to point that out in the docs.
(I don't think it is mentioned at the moment.)

When you really need to control order of evaluation, you can do it
using CASE or by pushing the whole expression into a function.  But
these defeat optimization so should be avoided if possible.
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Joel Burton"
Date:
Subject: Re: wierd AND condition evaluation for plpgsql
Next
From: Tom Lane
Date:
Subject: Re: self-tuning histograms