7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
* INTERFACE ROUTINES
13
13
* heap_create() - Create an uncataloged heap relation
@@ -1434,6 +1434,7 @@ StoreAttrDefault(Relation rel, AttrDefault *attrdef)
1434
1434
TargetEntry * te ;
1435
1435
Resdom * resdom ;
1436
1436
Node * expr ;
1437
+ Oid type ;
1437
1438
char * adbin ;
1438
1439
MemoryContext oldcxt ;
1439
1440
Relation adrel ;
@@ -1460,7 +1461,9 @@ start:;
1460
1461
te = (TargetEntry * ) lfirst (query -> targetList );
1461
1462
resdom = te -> resdom ;
1462
1463
expr = te -> expr ;
1464
+ type = exprType (expr );
1463
1465
1466
+ #if 0
1464
1467
if (IsA (expr , Const ))
1465
1468
{
1466
1469
if (((Const * ) expr )-> consttype != atp -> atttypid )
@@ -1474,6 +1477,26 @@ start:;
1474
1477
else if ((exprType (expr ) != atp -> atttypid )
1475
1478
&& !IS_BINARY_COMPATIBLE (exprType (expr ), atp -> atttypid ))
1476
1479
elog (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
+ goto start ;
1495
+ }
1496
+ else
1497
+ elog (ERROR , "DEFAULT clause type '%s' mismatched with column type '%s'" ,
1498
+ typeidTypeName (type ), typeidTypeName (atp -> atttypid ));
1499
+ }
1477
1500
1478
1501
adbin = nodeToString (expr );
1479
1502
oldcxt = MemoryContextSwitchTo ((MemoryContext ) CacheCxt );
0 commit comments