Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ec1aa4

Browse files
committed
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 beforebut had been broken due to premature freezing of the type of the testexpression. Per gripe from GÄbor SzÃcs.
1 parent8251e0b commit2ec1aa4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

‎src/backend/parser/parse_expr.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.178 2004/12/31 22:00:27 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.179 2005/01/12 17:32:36 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -646,17 +646,30 @@ transformExpr(ParseState *pstate, Node *expr)
646646

647647
/* transform the test expression, if any */
648648
arg=transformExpr(pstate, (Node*)c->arg);
649-
newc->arg= (Expr*)arg;
649+
650650
/* generate placeholder for test expression */
651651
if (arg)
652652
{
653+
/*
654+
* If test expression is an untyped literal, force it to
655+
* text. We have to do something now because we won't be
656+
* able to do this coercion on the placeholder. This is
657+
* not as flexible as what was done in 7.4 and before,
658+
* but it's good enough to handle the sort of silly
659+
* coding commonly seen.
660+
*/
661+
if (exprType(arg)==UNKNOWNOID)
662+
arg=coerce_to_common_type(pstate,arg,
663+
TEXTOID,"CASE");
653664
placeholder=makeNode(CaseTestExpr);
654665
placeholder->typeId=exprType(arg);
655666
placeholder->typeMod=exprTypmod(arg);
656667
}
657668
else
658669
placeholder=NULL;
659670

671+
newc->arg= (Expr*)arg;
672+
660673
/* transform the list of arguments */
661674
newargs=NIL;
662675
typeids=NIL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp