diff options
author | Thomas G. Lockhart <lockhart@fourpalms.org> | 1998-12-13 23:56:44 +0000 |
---|---|---|
committer | Thomas G. Lockhart <lockhart@fourpalms.org> | 1998-12-13 23:56:44 +0000 |
commit | 2b189aa9537f7b4a518c63a79555ce8bf644294c (patch) | |
tree | fa930f0f23180882c36868a851732cc895c70b94 /src | |
parent | 44cf948467d5f76632af26893ff048e17961ad1a (diff) | |
download | postgresql-2b189aa9537f7b4a518c63a79555ce8bf644294c.tar.gz postgresql-2b189aa9537f7b4a518c63a79555ce8bf644294c.zip |
Improve CASE statement support.
Try to label CASE columns for a SELECT if not specified with an AS clause.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/parser/parse_expr.c | 23 | ||||
-rw-r--r-- | src/backend/parser/parse_target.c | 15 |
2 files changed, 22 insertions, 16 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 8dcabc48dbb..acdf2d7d03d 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.37 1998/12/04 15:34:30 thomas Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.38 1998/12/13 23:56:43 thomas Exp $ * *------------------------------------------------------------------------- */ @@ -251,8 +251,7 @@ transformExpr(ParseState *pstate, Node *expr, int precedence) { /* - * look for a column name or a relation name (the default - * behavior) + * look for a column name or a relation name (the default behavior) */ result = transformIdent(pstate, expr, precedence); break; @@ -358,13 +357,6 @@ transformExpr(ParseState *pstate, Node *expr, int precedence) w->expr = (Node *)a; } lfirst(args) = transformExpr(pstate, (Node *) w, precedence); - - if (w->result == NULL) - { - A_Const *n = makeNode(A_Const); - n->val.type = T_Null; - w->result = (Node *)n; - } } if (c->defresult == NULL) @@ -413,7 +405,7 @@ transformExpr(ParseState *pstate, Node *expr, int precedence) } } - /* Convert default clause, if necessary */ + /* Convert default result clause, if necessary */ if (c->casetype != ptype) { if (! c->casetype) @@ -469,8 +461,13 @@ transformExpr(ParseState *pstate, Node *expr, int precedence) elog(ERROR,"WHEN clause must have a boolean result"); /* result is NULL for NULLIF() construct - thomas 1998-11-11 */ - if (w->result != NULL) - w->result = transformExpr(pstate, (Node *) w->result, precedence); + if (w->result == NULL) + { + A_Const *n = makeNode(A_Const); + n->val.type = T_Null; + w->result = (Node *)n; + } + w->result = transformExpr(pstate, (Node *) w->result, precedence); result = expr; break; } diff --git a/src/backend/parser/parse_target.c b/src/backend/parser/parse_target.c index e77183387d7..35d0db803a2 100644 --- a/src/backend/parser/parse_target.c +++ b/src/backend/parser/parse_target.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.31 1998/12/04 15:34:30 thomas Exp $ + * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.32 1998/12/13 23:56:44 thomas Exp $ * *------------------------------------------------------------------------- */ @@ -32,7 +32,7 @@ static List *ExpandAllTables(ParseState *pstate); -static char *FigureColname(Node *expr, Node *resval); +char *FigureColname(Node *expr, Node *resval); static Node *SizeTargetExpr(ParseState *pstate, Node *expr, @@ -867,7 +867,7 @@ ExpandAllTables(ParseState *pstate) * list, we have to guess. * */ -static char * +char * FigureColname(Node *expr, Node *resval) { switch (nodeTag(expr)) @@ -881,6 +881,15 @@ FigureColname(Node *expr, Node *resval) return ((FuncCall *) resval)->funcname; } break; + case T_CaseExpr: + { + char *name; + name = FigureColname(((CaseExpr *) expr)->defresult, resval); + if (!strcmp(name, "?column?")) + name = "case"; + return name; + } + break; default: break; } |