diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 4f41766..03a92f0 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -751,11 +751,13 @@ DefineDomain(CreateDomainStmt *stmt) ListCell *listptr; Oid basetypeoid; Oid old_type_oid; + Oid array_oid; Oid domaincoll; Form_pg_type baseType; int32 basetypeMod; Oid baseColl; ObjectAddress address; + char *array_type; /* Convert list of names to a name and namespace */ domainNamespace = QualifiedNameGetCreationNamespace(stmt->domainname, @@ -1022,6 +1024,14 @@ DefineDomain(CreateDomainStmt *stmt) } } + + /* + * OK, we're done checking, time to make the type. We must assign the + * array type OID ahead of calling TypeCreate, since the base type and + * array type each refer to the other. + */ + array_oid = AssignTypeArrayOid(); + /* * Have TypeCreate do all the real work. */ @@ -1046,7 +1056,7 @@ DefineDomain(CreateDomainStmt *stmt) analyzeProcedure, /* analyze procedure */ InvalidOid, /* no array element type */ false, /* this isn't an array */ - InvalidOid, /* no arrays for domains (yet) */ + array_oid, /* array type we are about to create */ basetypeoid, /* base type ID */ defaultValue, /* default type value (text) */ defaultValueBin, /* default type value (binary) */ @@ -1059,6 +1069,48 @@ DefineDomain(CreateDomainStmt *stmt) domaincoll); /* type's collation */ /* + * Create the array type that goes with it. + */ + array_type = makeArrayTypeName(domainName, domainNamespace); + +/* alignment must be 'i' or 'd' for arrays */ + alignment = (alignment == 'd') ? 'd' : 'i'; + + TypeCreate(array_oid,/* force assignment of this type OID */ + array_type,/* type name */ + domainNamespace,/* namespace */ + InvalidOid,/* relation oid (n/a here) */ + 0,/* relation kind (ditto) */ + GetUserId(),/* owner's ID */ + -1,/* internal size (always varlena) */ + TYPTYPE_DOMAIN,/* type-type (base type) */ + TYPCATEGORY_ARRAY,/* type-category (array) */ + false,/* array types are never preferred */ + delimiter,/* array element delimiter */ + F_ARRAY_IN,/* input procedure */ + F_ARRAY_OUT,/* output procedure */ + F_ARRAY_RECV,/* receive procedure */ + F_ARRAY_SEND,/* send procedure */ + InvalidOid,/* typmodin procedure */ + InvalidOid,/* typmodout procedure */ + F_ARRAY_TYPANALYZE,/* analyze procedure */ + address.objectId,/* element type ID */ + true,/* yes this is an array type */ + InvalidOid,/* no further array type */ + InvalidOid,/* base type ID */ + NULL,/* never a default type value */ + NULL,/* binary default isn't sent either */ + false,/* never passed by value */ + alignment,/* see above */ + 'x',/* ARRAY is always toastable */ + -1,/* typMod (Domains only) */ + 0,/* Array dimensions of typbasetype */ + false,/* Type NOT NULL */ + domaincoll);/* type's collation */ + + pfree(array_type); + + /* * Process constraints which refer to the domain ID returned by TypeCreate */ foreach(listptr, schema)