From: Tom Lane Date: Wed, 12 Jan 2005 17:32:36 +0000 (+0000) Subject: Re-allow an untyped literal as the test expression of a CASE, ie X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=2c4451397dda7bba3bc8caa853e18cb150227bf8;p=users%2Fbernd%2Fpostgres.git Re-allow an untyped literal as the test expression of a CASE, ie CASE 'a' WHEN 'a' THEN 1 ELSE 2 END. This worked in 7.4 and before but had been broken due to premature freezing of the type of the test expression. Per gripe from GÄbor SzÃcs. --- diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index ad0335b71b..ec323260c5 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -646,10 +646,21 @@ transformExpr(ParseState *pstate, Node *expr) /* transform the test expression, if any */ arg = transformExpr(pstate, (Node *) c->arg); - newc->arg = (Expr *) arg; + /* generate placeholder for test expression */ if (arg) { + /* + * If test expression is an untyped literal, force it to + * text. We have to do something now because we won't be + * able to do this coercion on the placeholder. This is + * not as flexible as what was done in 7.4 and before, + * but it's good enough to handle the sort of silly + * coding commonly seen. + */ + if (exprType(arg) == UNKNOWNOID) + arg = coerce_to_common_type(pstate, arg, + TEXTOID, "CASE"); placeholder = makeNode(CaseTestExpr); placeholder->typeId = exprType(arg); placeholder->typeMod = exprTypmod(arg); @@ -657,6 +668,8 @@ transformExpr(ParseState *pstate, Node *expr) else placeholder = NULL; + newc->arg = (Expr *) arg; + /* transform the list of arguments */ newargs = NIL; typeids = NIL;