Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a8790f

Browse files
author
Thomas G. Lockhart
committed
Use the new implicit type coersion techniques for matching up types
between columns and DEFAULT clauses.
1 parent 23cebf1 commit 1a8790f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/backend/catalog/heap.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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)
14341434
TargetEntry *te;
14351435
Resdom *resdom;
14361436
Node *expr;
1437+
Oid type;
14371438
char *adbin;
14381439
MemoryContext oldcxt;
14391440
Relation adrel;
@@ -1460,7 +1461,9 @@ start:;
14601461
te = (TargetEntry *) lfirst(query->targetList);
14611462
resdom = te->resdom;
14621463
expr = te->expr;
1464+
type = exprType(expr);
14631465

1466+
#if 0
14641467
if (IsA(expr, Const))
14651468
{
14661469
if (((Const *) expr)->consttype != atp->atttypid)
@@ -1474,6 +1477,26 @@ start:;
14741477
else if ((exprType(expr) != atp->atttypid)
14751478
&& !IS_BINARY_COMPATIBLE(exprType(expr), atp->atttypid))
14761479
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+
}
14771500

14781501
adbin = nodeToString(expr);
14791502
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);

0 commit comments

Comments
 (0)