77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.67 1998/11/27 19:51:48 vadim Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.68 1998/12/13 23:50:58 thomas Exp $
1111 *
1212 * INTERFACE ROUTINES
1313 *heap_create()- Create an uncataloged heap relation
@@ -1434,6 +1434,7 @@ StoreAttrDefault(Relation rel, AttrDefault *attrdef)
14341434TargetEntry * te ;
14351435Resdom * resdom ;
14361436Node * expr ;
1437+ Oid type ;
14371438char * adbin ;
14381439MemoryContext oldcxt ;
14391440Relation adrel ;
@@ -1460,7 +1461,9 @@ start:;
14601461te = (TargetEntry * )lfirst (query -> targetList );
14611462resdom = te -> resdom ;
14621463expr = te -> expr ;
1464+ type = exprType (expr );
14631465
1466+ #if 0
14641467if (IsA (expr ,Const ))
14651468{
14661469if (((Const * )expr )-> consttype != atp -> atttypid )
@@ -1474,6 +1477,26 @@ start:;
14741477else if ((exprType (expr )!= atp -> atttypid )
14751478&& !IS_BINARY_COMPATIBLE (exprType (expr ),atp -> atttypid ))
14761479elog (ERROR ,"DEFAULT: type mismatched" );
1480+ #endif
1481+
1482+ if (type != atp -> atttypid )
1483+ {
1484+ if (IS_BINARY_COMPATIBLE (type ,atp -> atttypid ))
1485+ ;/* use without change */
1486+ else if (can_coerce_type (1 ,& (type ),& (atp -> atttypid )))
1487+ expr = coerce_type (NULL , (Node * )expr ,type ,atp -> atttypid );
1488+ else if (IsA (expr ,Const ))
1489+ {
1490+ if (* cast != 0 )
1491+ elog (ERROR ,"DEFAULT clause const type '%s' mismatched with column type '%s'" ,
1492+ typeidTypeName (type ),typeidTypeName (atp -> atttypid ));
1493+ sprintf (cast ,":: %s" ,typeidTypeName (atp -> atttypid ));
1494+ gotostart ;
1495+ }
1496+ else
1497+ elog (ERROR ,"DEFAULT clause type '%s' mismatched with column type '%s'" ,
1498+ typeidTypeName (type ),typeidTypeName (atp -> atttypid ));
1499+ }
14771500
14781501adbin = nodeToString (expr );
14791502oldcxt = MemoryContextSwitchTo ((MemoryContext )CacheCxt );