Commit 052c2eaa authored by Tom Lane's avatar Tom Lane

Simplify and clean up FigureColname; make it work without coredumping

for TypeCast case.
parent ec7ddc15
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.71 2001/09/10 14:53:10 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.72 2001/09/17 01:06:36 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
static List *ExpandAllTables(ParseState *pstate); static List *ExpandAllTables(ParseState *pstate);
static char *FigureColname(Node *expr, Node *resval); static char *FigureColname(Node *node);
/* /*
...@@ -64,12 +64,11 @@ transformTargetEntry(ParseState *pstate, ...@@ -64,12 +64,11 @@ transformTargetEntry(ParseState *pstate,
if (colname == NULL) if (colname == NULL)
{ {
/* /*
* Generate a suitable column name for a column without any * Generate a suitable column name for a column without any
* explicit 'AS ColumnName' clause. * explicit 'AS ColumnName' clause.
*/ */
colname = FigureColname(expr, node); colname = FigureColname(node);
} }
resnode = makeResdom((AttrNumber) pstate->p_last_resno++, resnode = makeResdom((AttrNumber) pstate->p_last_resno++,
...@@ -455,21 +454,21 @@ ExpandAllTables(ParseState *pstate) ...@@ -455,21 +454,21 @@ ExpandAllTables(ParseState *pstate)
* list, we have to guess a suitable name. The SQL spec provides some * list, we have to guess a suitable name. The SQL spec provides some
* guidance, but not much... * guidance, but not much...
* *
* Note that the argument is the *untransformed* parse tree for the target
* item. This is a shade easier to work with than the transformed tree.
*/ */
static char * static char *
FigureColname(Node *expr, Node *resval) FigureColname(Node *node)
{ {
/* Some of these are easiest to do with the untransformed node */ if (node == NULL)
switch (nodeTag(resval)) return "?column?";
switch (nodeTag(node))
{ {
case T_TypeCast:
return( ( ((Ident *) ((TypeCast *) resval)->arg)->name));
case T_Ident: case T_Ident:
return ((Ident *) resval)->name; return ((Ident *) node)->name;
case T_Attr: case T_Attr:
{ {
List *attrs = ((Attr *) resval)->attrs; List *attrs = ((Attr *) node)->attrs;
if (attrs) if (attrs)
{ {
...@@ -479,23 +478,15 @@ FigureColname(Node *expr, Node *resval) ...@@ -479,23 +478,15 @@ FigureColname(Node *expr, Node *resval)
} }
} }
break; break;
default: case T_FuncCall:
break; return ((FuncCall *) node)->funcname;
} case T_TypeCast:
/* Otherwise, work with the transformed node */ return FigureColname(((TypeCast *) node)->arg);
switch (nodeTag(expr))
{
case T_Expr:
if (((Expr *) expr)->opType == FUNC_EXPR && IsA(resval, FuncCall))
return ((FuncCall *) resval)->funcname;
break;
case T_Aggref:
return ((Aggref *) expr)->aggname;
case T_CaseExpr: case T_CaseExpr:
{ {
char *name; char *name;
name = FigureColname(((CaseExpr *) expr)->defresult, resval); name = FigureColname(((CaseExpr *) node)->defresult);
if (strcmp(name, "?column?") == 0) if (strcmp(name, "?column?") == 0)
name = "case"; name = "case";
return name; return name;
...@@ -504,6 +495,5 @@ FigureColname(Node *expr, Node *resval) ...@@ -504,6 +495,5 @@ FigureColname(Node *expr, Node *resval)
default: default:
break; break;
} }
return "?column?"; return "?column?";
} }
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