Commit 2ec1aa4c authored by Tom Lane's avatar Tom Lane

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.
parent 8251e0b2
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.178 2004/12/31 22:00:27 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.179 2005/01/12 17:32:36 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -646,10 +646,21 @@ transformExpr(ParseState *pstate, Node *expr) ...@@ -646,10 +646,21 @@ transformExpr(ParseState *pstate, Node *expr)
/* transform the test expression, if any */ /* transform the test expression, if any */
arg = transformExpr(pstate, (Node *) c->arg); arg = transformExpr(pstate, (Node *) c->arg);
newc->arg = (Expr *) arg;
/* generate placeholder for test expression */ /* generate placeholder for test expression */
if (arg) 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 = makeNode(CaseTestExpr);
placeholder->typeId = exprType(arg); placeholder->typeId = exprType(arg);
placeholder->typeMod = exprTypmod(arg); placeholder->typeMod = exprTypmod(arg);
...@@ -657,6 +668,8 @@ transformExpr(ParseState *pstate, Node *expr) ...@@ -657,6 +668,8 @@ transformExpr(ParseState *pstate, Node *expr)
else else
placeholder = NULL; placeholder = NULL;
newc->arg = (Expr *) arg;
/* transform the list of arguments */ /* transform the list of arguments */
newargs = NIL; newargs = NIL;
typeids = NIL; typeids = NIL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment