88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.102 2003/05/31 19:03:34 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.103 2003/06/25 04: 19:24 momjian Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -177,19 +177,24 @@ transformTargetList(ParseState *pstate, List *targetlist)
177177false));
178178}
179179}
180- else if (IsA (res -> val ,InsertDefault ))
180+ else if (IsA (res -> val ,SetToDefault ))
181181{
182- InsertDefault * newnode = makeNode (InsertDefault );
183-
184182/*
185- * If this is a DEFAULT element, we make a junk entry which
186- * will get dropped on return to transformInsertStmt().
183+ * If this is a DEFAULT element, we make a standard entry using
184+ * the default for the target expression. rewriteTargetList will
185+ * substitute the columns default for this expression.
187186 */
188- p_target = lappend (p_target ,newnode );
187+ p_target = lappend (p_target ,
188+ makeTargetEntry (makeResdom ((AttrNumber )pstate -> p_next_resno ++ ,
189+ UNKNOWNOID ,
190+ -1 ,
191+ res -> name ,
192+ false),
193+ (Expr * )res -> val ));
189194}
190195else
191196{
192- /* Everything else but ColumnRef andInsertDefault */
197+ /* Everything else but ColumnRef andSetToDefault */
193198p_target = lappend (p_target ,
194199transformTargetEntry (pstate ,
195200res -> val ,
@@ -321,9 +326,10 @@ updateTargetListEntry(ParseState *pstate,
321326int attrno ,
322327List * indirection )
323328{
324- Oid type_id = exprType (( Node * ) tle -> expr ); /* type of value provided */
329+ Oid type_id ; /* type of value provided */
325330Oid attrtype ;/* type of target column */
326331int32 attrtypmod ;
332+ bool isDefault = false;
327333Resdom * resnode = tle -> resdom ;
328334Relation rd = pstate -> p_target_relation ;
329335
@@ -333,6 +339,17 @@ updateTargetListEntry(ParseState *pstate,
333339attrtype = attnumTypeId (rd ,attrno );
334340attrtypmod = rd -> rd_att -> attrs [attrno - 1 ]-> atttypmod ;
335341
342+ /* The type of the default column is equivalent to that of the column */
343+ if (tle -> expr != NULL && IsA (tle -> expr ,SetToDefault ))
344+ {
345+ type_id = attrtype ;
346+ isDefault = true;
347+ }
348+
349+ /* Otherwise the expression holds the type */
350+ else
351+ type_id = exprType ((Node * )tle -> expr );
352+
336353/*
337354 * If there are subscripts on the target column, prepare an array
338355 * assignment expression. This will generate an array value that the
@@ -383,7 +400,7 @@ updateTargetListEntry(ParseState *pstate,
383400 * coercion. But accept InvalidOid, which indicates the source is
384401 * a NULL constant. (XXX is that still true?)
385402 */
386- if (type_id != InvalidOid )
403+ if (! isDefault && type_id != InvalidOid )
387404{
388405tle -> expr = (Expr * )
389406coerce_to_target_type (pstate ,