77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.38 1999/05/22 04:12:28 momjian Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.39 1999/05/23 21:42:09 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
3232
3333
3434static List * ExpandAllTables (ParseState * pstate );
35- char * FigureColname (Node * expr ,Node * resval );
36-
35+ static char * FigureColname (Node * expr ,Node * resval );
3736static Node * SizeTargetExpr (ParseState * pstate ,
3837Node * expr ,
3938Oid attrtype ,
4039int32 attrtypmod );
4140
42- static TargetEntry *
43- MakeTargetEntryCase (ParseState * pstate ,
44- ResTarget * res );
4541
4642/* MakeTargetEntryIdent()
4743 * Transforms an Ident Node to a Target Entry
@@ -66,8 +62,13 @@ MakeTargetEntryIdent(ParseState *pstate,
6662Oid attrtype_target ;
6763TargetEntry * tent = makeNode (TargetEntry );
6864
69- if (pstate -> p_is_insert )
65+ if (pstate -> p_is_insert && ! resjunk )
7066{
67+ /* Assign column name of destination column to the new TLE.
68+ * XXX this is probably WRONG in INSERT ... SELECT case,
69+ * since handling of GROUP BY and so forth probably should use
70+ * the source table's names not the destination's names.
71+ */
7172if (pstate -> p_insert_columns != NIL )
7273{
7374Ident * id = lfirst (pstate -> p_insert_columns );
@@ -79,7 +80,7 @@ MakeTargetEntryIdent(ParseState *pstate,
7980elog (ERROR ,"INSERT has more expressions than target columns" );
8081}
8182
82- if (pstate -> p_is_insert || pstate -> p_is_update )
83+ if (( pstate -> p_is_insert || pstate -> p_is_update ) && ! resjunk )
8384{
8485Oid attrtype_id ;
8586int resdomno_id ,
@@ -208,7 +209,7 @@ MakeTargetEntryExpr(ParseState *pstate,
208209type_mod = -1 ;
209210
210211/* Process target columns that will be receiving results */
211- if (pstate -> p_is_insert || pstate -> p_is_update )
212+ if (( pstate -> p_is_insert || pstate -> p_is_update ) && ! resjunk )
212213{
213214
214215/*
@@ -870,7 +871,7 @@ ExpandAllTables(ParseState *pstate)
870871 * list, we have to guess.
871872 *
872873 */
873- char *
874+ static char *
874875FigureColname (Node * expr ,Node * resval )
875876{
876877switch (nodeTag (expr ))