Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b806b3d

Browse files
author
Thomas G. Lockhart
committed
Allow insert statements to have every column
supplied by a DEFAULT clause. Enables INSERT INTO TABLE DEFAULT VALUES...
1 parent dfab686 commit b806b3d

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/backend/parser/analyze.c

+21-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.85 1998/09/01 04:30:15 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.86 1998/09/03 14:21:06 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -269,8 +269,8 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
269269
int ndef = pstate->p_target_relation->rd_att->constr->num_defval;
270270

271271
/*
272-
* if stmt->cols == NIL then makeTargetNames returns list of all
273-
* attrs: have to shorter icolumns list...
272+
* if stmt->cols == NIL then makeTargetNames returns list of all attrs.
273+
* May have to shorten icolumns list...
274274
*/
275275
if (stmt->cols == NIL)
276276
{
@@ -279,11 +279,26 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
279279

280280
foreach(extrl, icolumns)
281281
{
282+
/*
283+
* decrements first, so if we started with zero items
284+
* it will now be negative
285+
*/
282286
if (--i <= 0)
283287
break;
284288
}
285-
freeList(lnext(extrl));
286-
lnext(extrl) = NIL;
289+
/*
290+
* this an index into the targetList,
291+
* so make sure we had one to start...
292+
*/
293+
if (i >= 0)
294+
{
295+
freeList(lnext(extrl));
296+
lnext(extrl) = NIL;
297+
}
298+
else
299+
{
300+
icolumns = NIL;
301+
}
287302
}
288303

289304
while (ndef-- > 0)
@@ -295,7 +310,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
295310
foreach(tl, icolumns)
296311
{
297312
id = (Ident *) lfirst(tl);
298-
if (!namestrcmp(&(att[defval[ndef].adnum - 1]->attname), id->name))
313+
if (namestrcmp(&(att[defval[ndef].adnum - 1]->attname), id->name) == 0)
299314
break;
300315
}
301316
if (tl != NIL) /* something given for this attr */

0 commit comments

Comments
 (0)