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

Commit052c2ea

Browse files
committed
Simplify and clean up FigureColname; make it work without coredumping
for TypeCast case.
1 parentec7ddc1 commit052c2ea

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

‎src/backend/parser/parse_target.c

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.71 2001/09/10 14:53:10 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.72 2001/09/17 01:06:36 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -26,7 +26,7 @@
2626

2727

2828
staticList*ExpandAllTables(ParseState*pstate);
29-
staticchar*FigureColname(Node*expr,Node*resval);
29+
staticchar*FigureColname(Node*node);
3030

3131

3232
/*
@@ -64,12 +64,11 @@ transformTargetEntry(ParseState *pstate,
6464

6565
if (colname==NULL)
6666
{
67-
6867
/*
6968
* Generate a suitable column name for a column without any
7069
* explicit 'AS ColumnName' clause.
7170
*/
72-
colname=FigureColname(expr,node);
71+
colname=FigureColname(node);
7372
}
7473

7574
resnode=makeResdom((AttrNumber)pstate->p_last_resno++,
@@ -455,21 +454,21 @@ ExpandAllTables(ParseState *pstate)
455454
* list, we have to guess a suitable name. The SQL spec provides some
456455
* guidance, but not much...
457456
*
457+
* Note that the argument is the *untransformed* parse tree for the target
458+
* item. This is a shade easier to work with than the transformed tree.
458459
*/
459460
staticchar*
460-
FigureColname(Node*expr,Node*resval)
461+
FigureColname(Node*node)
461462
{
462-
/* Some of these are easiest to do with the untransformed node */
463-
switch (nodeTag(resval))
463+
if (node==NULL)
464+
return"?column?";
465+
switch (nodeTag(node))
464466
{
465-
caseT_TypeCast:
466-
return( ( ((Ident*) ((TypeCast*)resval)->arg)->name));
467-
468467
caseT_Ident:
469-
return ((Ident*)resval)->name;
468+
return ((Ident*)node)->name;
470469
caseT_Attr:
471470
{
472-
List*attrs= ((Attr*)resval)->attrs;
471+
List*attrs= ((Attr*)node)->attrs;
473472

474473
if (attrs)
475474
{
@@ -479,23 +478,15 @@ FigureColname(Node *expr, Node *resval)
479478
}
480479
}
481480
break;
482-
default:
483-
break;
484-
}
485-
/* Otherwise, work with the transformed node */
486-
switch (nodeTag(expr))
487-
{
488-
caseT_Expr:
489-
if (((Expr*)expr)->opType==FUNC_EXPR&&IsA(resval,FuncCall))
490-
return ((FuncCall*)resval)->funcname;
491-
break;
492-
caseT_Aggref:
493-
return ((Aggref*)expr)->aggname;
481+
caseT_FuncCall:
482+
return ((FuncCall*)node)->funcname;
483+
caseT_TypeCast:
484+
returnFigureColname(((TypeCast*)node)->arg);
494485
caseT_CaseExpr:
495486
{
496487
char*name;
497488

498-
name=FigureColname(((CaseExpr*)expr)->defresult,resval);
489+
name=FigureColname(((CaseExpr*)node)->defresult);
499490
if (strcmp(name,"?column?")==0)
500491
name="case";
501492
returnname;
@@ -504,6 +495,5 @@ FigureColname(Node *expr, Node *resval)
504495
default:
505496
break;
506497
}
507-
508498
return"?column?";
509499
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp