From 2ec1aa4cb8cb053d197480eaa74dac07857585f2 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 12 Jan 2005 17:32:36 +0000 Subject: [PATCH] =?UTF-8?q?Re-allow=20an=20untyped=20literal=20as=20the=20?= =?UTF-8?q?test=20expression=20of=20a=20CASE,=20ie=20CASE=20'a'=20WHEN=20'?= =?UTF-8?q?a'=20THEN=201=20ELSE=202=20END.=20=20This=20worked=20in=207.4?= =?UTF-8?q?=20and=20before=20but=20had=20been=20broken=20due=20to=20premat?= =?UTF-8?q?ure=20freezing=20of=20the=20type=20of=20the=20test=20expression?= =?UTF-8?q?.=20=20Per=20gripe=20from=20G=C3=84bor=20Sz=C3=83cs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/parser/parse_expr.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index c00dc72ac3..6676ae0a4b 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -8,7 +8,7 @@ * * * 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) /* 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; -- GitLab