David Rowley <dgrowleyml@gmail.com> writes:
> I've not looked at the code to see if this would be practical or not,
> but I wonder if we could reduce these bug reports by using the new
> soft error reporting that's now done in the input functions to have
> constant folding just silently not do any folding for the expression
> if a cast fails.
Sadly, I doubt that would cover enough of the problem space to make
much difference to people who try to do this sort of thing.
> ... I imagine most people who
> have had them fail during constant folding have just redesigned or
> found some hack to prevent the folding from taking place anyway.
Yeah. The given query looks like it was already hacked to avoid
constant-folding, though I wonder if whoever wrote it really understood
that. Otherwise it'd be a lot more natural to use something like CASE.
Anyway, adding OFFSET 0 to suppress sub-select folding is probably
the best answer here.
regards, tom lane