I wrote: > Alexander Pyhalov <a.pyha...@postgrespro.ru> writes: >> Do we we need to inspect only case_arg_cxt->state? Can we assert that >> collation == case_arg_cxt->collation?
> Perhaps, but: > ... Oh, actually there's a third point: the shakiest part of this logic is the assumption that we've correctly matched a CaseTestExpr to its source CaseExpr. Seeing that inlining and constant-folding can mash things to the point where a WHEN expression doesn't look like "CaseTestExpr = RHS", it's a little nervous-making to assume there couldn't be another CASE in between. While there's not known problems of this sort, if it did happen I'd prefer this code to react as "don't push down", not as "assertion failure". (There's been speculation in the past about whether we could find a more bulletproof representation of this kind of CaseExpr. We've not succeeded at that yet though.) regards, tom lane