diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-03-19 02:18:25 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-03-19 02:18:25 +0000 |
commit | d3788c330517af301576a14bdd71f26da3b0e1c0 (patch) | |
tree | accb7af74b71d962496a250d1eb6cbec71bffd48 /src/backend/commands/creatinh.c | |
parent | 525b19399c629455bdcd63c9879f7c75f7ae3d25 (diff) | |
download | postgresql-d3788c330517af301576a14bdd71f26da3b0e1c0.tar.gz postgresql-d3788c330517af301576a14bdd71f26da3b0e1c0.zip |
Add DOMAIN support. Includes manual pages and regression tests, from
Rod Taylor.
Diffstat (limited to 'src/backend/commands/creatinh.c')
-rw-r--r-- | src/backend/commands/creatinh.c | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/src/backend/commands/creatinh.c b/src/backend/commands/creatinh.c index bb80487dbb4..ae2a90c9311 100644 --- a/src/backend/commands/creatinh.c +++ b/src/backend/commands/creatinh.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.85 2002/03/07 16:35:34 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.86 2002/03/19 02:18:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -39,7 +39,7 @@ static bool change_varattnos_of_a_node(Node *node, const AttrNumber *newattno); static void StoreCatalogInheritance(Oid relationId, List *supers); static int findAttrByName(const char *attributeName, List *schema); static void setRelhassubclassInRelation(Oid relationId, bool relhassubclass); - +static List *MergeDomainAttributes(List *schema); /* ---------------------------------------------------------------- * DefineRelation @@ -70,6 +70,13 @@ DefineRelation(CreateStmt *stmt, char relkind) StrNCpy(relname, stmt->relname, NAMEDATALEN); /* + * Inherit domain attributes into the known columns before table inheritance + * applies it's changes otherwise we risk adding double constraints + * to a domain thats inherited. + */ + schema = MergeDomainAttributes(schema); + + /* * Look up inheritance ancestors and generate relation schema, * including inherited attributes. */ @@ -237,6 +244,66 @@ TruncateRelation(char *name) heap_truncate(name); } + +/* + * MergeDomainAttributes + * Returns a new table schema with the constraints, types, and other + * attributes of the domain resolved for fields using the domain as + * their type. + * + * Defaults are pulled out by the table attribute as required, similar to + * how all types defaults are processed. + */ +static List * +MergeDomainAttributes(List *schema) +{ + List *entry; + + /* + * Loop through the table elements supplied. These should + * never include inherited domains else they'll be + * double (or more) processed. + */ + foreach(entry, schema) + { + ColumnDef *coldef = lfirst(entry); + HeapTuple tuple; + Form_pg_type typeTup; + + + tuple = SearchSysCache(TYPENAME, + CStringGetDatum(coldef->typename->name), + 0,0,0); + + if (!HeapTupleIsValid(tuple)) + elog(ERROR, "MergeDomainAttributes: Type %s does not exist", + coldef->typename->name); + + typeTup = (Form_pg_type) GETSTRUCT(tuple); + if (typeTup->typtype == 'd') { + /* + * This is a domain, lets force the properties of the domain on to + * the new column. + */ + + /* Enforce the typmod value */ + coldef->typename->typmod = typeTup->typmod; + + /* Enforce type NOT NULL || column definition NOT NULL -> NOT NULL */ + coldef->is_not_null |= typeTup->typnotnull; + + /* Enforce the element type in the event the domain is an array + * + * BUG: How do we fill out arrayBounds and attrname from typelem and typNDimms? + */ + + } + ReleaseSysCache(tuple); + } + + return schema; +} + /*---------- * MergeAttributes * Returns new schema given initial schema and superclasses. |