aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/functioncmds.c17
-rw-r--r--src/backend/commands/typecmds.c18
2 files changed, 23 insertions, 12 deletions
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index bd977d2b3cb..e10d4fb0151 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1657,6 +1657,23 @@ CreateCast(CreateCastStmt *stmt)
ereport(ERROR,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("array data types are not binary-compatible")));
+
+ /*
+ * We also disallow creating binary-compatibility casts involving
+ * domains. Casting from a domain to its base type is already
+ * allowed, and casting the other way ought to go through domain
+ * coercion to permit constraint checking. Again, if you're intent on
+ * having your own semantics for that, create a no-op cast function.
+ *
+ * NOTE: if we were to relax this, the above checks for composites
+ * etc. would have to be modified to look through domains to their
+ * base types.
+ */
+ if (sourcetyptype == TYPTYPE_DOMAIN ||
+ targettyptype == TYPTYPE_DOMAIN)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+ errmsg("domain data types must not be marked binary-compatible")));
}
/*
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 25503bda4f4..46b156e09a3 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -525,14 +525,12 @@ DefineType(List *names, List *parameters)
/*
* now have TypeCreate do all the real work.
+ *
+ * Note: the pg_type.oid is stored in user tables as array elements (base
+ * types) in ArrayType and in composite types in DatumTupleFields. This
+ * oid must be preserved by binary upgrades.
*/
typoid =
-
- /*
- * The pg_type.oid is stored in user tables as array elements (base types)
- * in ArrayType and in composite types in DatumTupleFields. This oid must
- * be preserved by binary upgrades.
- */
TypeCreate(InvalidOid, /* no predetermined type OID */
typeName, /* type name */
typeNamespace, /* namespace */
@@ -746,7 +744,6 @@ DefineDomain(CreateDomainStmt *stmt)
Oid sendProcedure;
Oid analyzeProcedure;
bool byValue;
- Oid typelem;
char category;
char delimiter;
char alignment;
@@ -831,9 +828,6 @@ DefineDomain(CreateDomainStmt *stmt)
/* Type Category */
category = baseType->typcategory;
- /* Array element type (in case base type is an array) */
- typelem = baseType->typelem;
-
/* Array element Delimiter */
delimiter = baseType->typdelim;
@@ -1033,7 +1027,7 @@ DefineDomain(CreateDomainStmt *stmt)
InvalidOid, /* typmodin procedure - none */
InvalidOid, /* typmodout procedure - none */
analyzeProcedure, /* analyze procedure */
- typelem, /* element type ID */
+ InvalidOid, /* no array element type */
false, /* this isn't an array */
InvalidOid, /* no arrays for domains (yet) */
basetypeoid, /* base type ID */
@@ -1670,7 +1664,7 @@ AlterDomainDefault(List *names, Node *defaultRaw)
typTup->typmodin,
typTup->typmodout,
typTup->typanalyze,
- typTup->typelem,
+ InvalidOid,
false, /* a domain isn't an implicit array */
typTup->typbasetype,
defaultExpr,