summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas G. Lockhart <lockhart@fourpalms.org>1998-12-14 00:13:26 +0000
committerThomas G. Lockhart <lockhart@fourpalms.org>1998-12-14 00:13:26 +0000
commitb5b5f0ddc9f15f87d61457cb8037efa1a14a130d (patch)
treef8a3d5e97001a686e728ca3d585a149b164c982e
parent3f1c32e2f10a0f93a9de8aef4ac4d71d80b38f8a (diff)
Use the new implicit type coersion techniques for matching up types
between columns and DEFAULT clauses.
-rw-r--r--src/backend/catalog/heap.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 9cfc267d9af..2719b55d063 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.64.2.2 1998/11/17 14:42:52 thomas Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.64.2.3 1998/12/14 00:13:26 thomas Exp $
*
* INTERFACE ROUTINES
* heap_create() - Create an uncataloged heap relation
@@ -1434,6 +1434,7 @@ StoreAttrDefault(Relation rel, AttrDefault *attrdef)
TargetEntry *te;
Resdom *resdom;
Node *expr;
+ Oid type;
char *adbin;
MemoryContext oldcxt;
Relation adrel;
@@ -1460,7 +1461,9 @@ start:;
te = (TargetEntry *) lfirst(query->targetList);
resdom = te->resdom;
expr = te->expr;
+ type = exprType(expr);
+#if 0
if (IsA(expr, Const))
{
if (((Const *) expr)->consttype != atp->atttypid)
@@ -1474,6 +1477,26 @@ start:;
else if ((exprType(expr) != atp->atttypid)
&& !IS_BINARY_COMPATIBLE(exprType(expr), atp->atttypid))
elog(ERROR, "DEFAULT: type mismatched");
+#endif
+
+ if (type != atp->atttypid)
+ {
+ if (IS_BINARY_COMPATIBLE(type, atp->atttypid))
+ ; /* use without change */
+ else if (can_coerce_type(1, &(type), &(atp->atttypid)))
+ expr = coerce_type(NULL, (Node *)expr, type, atp->atttypid);
+ else if (IsA(expr, Const))
+ {
+ if (*cast != 0)
+ elog(ERROR, "DEFAULT clause const type '%s' mismatched with column type '%s'",
+ typeidTypeName(type), typeidTypeName(atp->atttypid));
+ sprintf(cast, ":: %s", typeidTypeName(atp->atttypid));
+ goto start;
+ }
+ else
+ elog(ERROR, "DEFAULT clause type '%s' mismatched with column type '%s'",
+ typeidTypeName(type), typeidTypeName(atp->atttypid));
+ }
adbin = nodeToString(expr);
oldcxt = MemoryContextSwitchTo((MemoryContext) CacheCxt);