diff options
author | Bruce Momjian <bruce@momjian.us> | 2002-03-06 20:35:02 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2002-03-06 20:35:02 +0000 |
commit | 01c76f7411c24b11e4ab36a9fe5f5017dc33be78 (patch) | |
tree | 279d40bc7e04a02e9cd9124ff0f21a79deb50e90 /src/backend/commands/creatinh.c | |
parent | 3d9f865e94b2e7b926ef083dd555ecc7d33bccf9 (diff) | |
download | postgresql-01c76f7411c24b11e4ab36a9fe5f5017dc33be78.tar.gz postgresql-01c76f7411c24b11e4ab36a9fe5f5017dc33be78.zip |
Ok. Updated patch attached.
- domain.patch -> source patch against pgsql in cvs
- drop_domain.sgml and create_domain.sgml -> New doc/src/sgml/ref docs
- dominfo.txt -> basic domain related queries I used for testing
[ ADDED TO /doc]
Enables domains of array elements -> CREATE DOMAIN dom int4[3][2];
Uses a typbasetype column to describe the origin of the domain.
Copies data to attnotnull rather than processing in execMain().
Some documentation differences from earlier.
If this is approved, I'll start working on pg_dump, and a \dD <domain>
option in psql, and regression tests. I don't really feel like doing
those until the system table structure settles for pg_type.
CHECKS when added, will also be copied to to the table attributes. FK
Constraints (if I ever figure out how) will be done similarly. Both
will lbe handled by MergeDomainAttributes() which is called shortly
before MergeAttributes().
Rod Taylor
Diffstat (limited to 'src/backend/commands/creatinh.c')
-rw-r--r-- | src/backend/commands/creatinh.c | 93 |
1 files changed, 91 insertions, 2 deletions
diff --git a/src/backend/commands/creatinh.c b/src/backend/commands/creatinh.c index 27535429c39..586cee63cce 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.83 2002/03/06 06:09:31 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.84 2002/03/06 20:34:46 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); /* + * Merge domain attributes into the known columns before 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,88 @@ TruncateRelation(char *name) heap_truncate(name); } + +/* + * MergeDomainAttributes + * Returns a new schema with the constraints, types, and other + * attributes of the domain resolved. + * + * Defaults are processed at execution time by taking the default of + * the type (domain) if it is null. This does not need to be merged + * here. + */ +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); + +//typedef struct TypeName +//{ + //NodeTag type; + //char *name; /* name of the type */ + //bool timezone; /* timezone specified? */ + //bool setof; /* is a set? */ + //int32 typmod; /* type modifier */ + //List *arrayBounds; /* array bounds */ + //char *attrname; /* field name when using %TYPE */ +//} TypeName; + +// ColumnDef +// NodeTag type; +// char *colname; /* name of column */ +// TypeName *typename; /* type of column */ +// bool is_not_null; /* NOT NULL constraint specified? */ +// Node *raw_default; /* default value (untransformed parse +// * tree) */ +// char *cooked_default; /* nodeToString representation */ +// List *constraints; /* other constraints on column */ + + } + + return schema; +} + /*---------- * MergeAttributes * Returns new schema given initial schema and superclasses. |