aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/typecmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-10-21 16:07:17 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2010-10-21 16:07:17 -0400
commit529cb267a6843a6a8190c86b75d091771d99d6a9 (patch)
treeaea2869f7fb92b00c25e67d20d4326b77720b27c /src/backend/commands/typecmds.c
parent572ab1a542c170ddd2e4c30ef472e13f531b64a4 (diff)
downloadpostgresql-529cb267a6843a6a8190c86b75d091771d99d6a9.tar.gz
postgresql-529cb267a6843a6a8190c86b75d091771d99d6a9.zip
Improve handling of domains over arrays.
This patch eliminates various bizarre behaviors caused by sloppy thinking about the difference between a domain type and its underlying array type. In particular, the operation of updating one element of such an array has to be considered as yielding a value of the underlying array type, *not* a value of the domain, because there's no assurance that the domain's CHECK constraints are still satisfied. If we're intending to store the result back into a domain column, we have to re-cast to the domain type so that constraints are re-checked. For similar reasons, such a domain can't be blindly matched to an ANYARRAY polymorphic parameter, because the polymorphic function is likely to apply array-ish operations that could invalidate the domain constraints. For the moment, we just forbid such matching. We might later wish to insert an automatic downcast to the underlying array type, but such a change should also change matching of domains to ANYELEMENT for consistency. To ensure that all such logic is rechecked, this patch removes the original hack of setting a domain's pg_type.typelem field to match its base type; the typelem will always be zero instead. In those places where it's really okay to look through the domain type with no other logic changes, use the newly added get_base_element_type function in place of get_element_type. catversion bumped due to change in pg_type contents. Per bug #5717 from Richard Huxton and subsequent discussion.
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r--src/backend/commands/typecmds.c18
1 files changed, 6 insertions, 12 deletions
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,