Joseph Shraibman <jks(at)selectacast(dot)net> writes:
> Does plpgsql not short circuit its logic?
We make no guarantees about evaluation order. In the particular
case at hand, you're losing because plpgsql has to evaluate all
the variables that it's going to pass into the SQL engine for
that expression. Break it into two statements ...
regards, tom lane