From d3788c330517af301576a14bdd71f26da3b0e1c0 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Tue, 19 Mar 2002 02:18:25 +0000 Subject: [PATCH] Add DOMAIN support. Includes manual pages and regression tests, from Rod Taylor. --- doc/src/sgml/catalogs.sgml | 49 +++- doc/src/sgml/ref/allfiles.sgml | 4 +- doc/src/sgml/ref/comment.sgml | 15 +- doc/src/sgml/ref/create_domain.sgml | 231 ++++++++++++++++ doc/src/sgml/ref/drop_domain.sgml | 167 ++++++++++++ doc/src/sgml/reference.sgml | 6 +- src/backend/catalog/heap.c | 159 ++++++----- src/backend/catalog/pg_type.c | 70 ++++- src/backend/commands/creatinh.c | 71 ++++- src/backend/commands/define.c | 364 ++++++++++++++++++++++++- src/backend/commands/remove.c | 59 +++- src/backend/nodes/copyfuncs.c | 19 +- src/backend/nodes/equalfuncs.c | 18 +- src/backend/optimizer/prep/preptlist.c | 52 ++-- src/backend/parser/gram.y | 81 +++++- src/backend/parser/keywords.c | 3 +- src/backend/parser/parse_coerce.c | 31 ++- src/backend/parser/parse_expr.c | 7 +- src/backend/tcop/postgres.c | 7 +- src/backend/tcop/utility.c | 20 +- src/backend/utils/adt/format_type.c | 28 +- src/backend/utils/cache/lsyscache.c | 65 +++-- src/backend/utils/cache/relcache.c | 10 +- src/include/catalog/heap.h | 10 +- src/include/catalog/pg_attribute.h | 17 +- src/include/catalog/pg_class.h | 4 +- src/include/catalog/pg_type.h | 257 ++++++++++------- src/include/commands/defrem.h | 4 +- src/include/nodes/nodes.h | 3 +- src/include/nodes/parsenodes.h | 22 +- src/include/parser/parse_coerce.h | 3 +- src/include/utils/lsyscache.h | 4 +- src/test/regress/expected/domain.out | 114 ++++++++ src/test/regress/parallel_schedule | 2 +- src/test/regress/serial_schedule | 4 +- src/test/regress/sql/domain.sql | 111 ++++++++ 36 files changed, 1805 insertions(+), 286 deletions(-) create mode 100644 doc/src/sgml/ref/create_domain.sgml create mode 100644 doc/src/sgml/ref/drop_domain.sgml create mode 100644 src/test/regress/expected/domain.out create mode 100644 src/test/regress/sql/domain.sql diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index d785121a047..451c9dcaa8a 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -1,6 +1,6 @@ @@ -2510,6 +2510,53 @@ + + typbasetype + oid + + + typbasetype is the type that this one is based + on. Normally references the domains parent type, and is 0 otherwise. + + + + + typnotnull + boolean + + + typnotnull represents a NOT NULL + constraint on a type. Used for domains only. + + + + + typmod + integer + + + typmod records type-specific data + supplied at table creation time (for example, the maximum + length of a varchar column). It is passed to + type-specific input and output functions as the third + argument. The value will generally be -1 for types that do not + need typmod. This data is copied to + pg_attribute.atttypmod on creation + of a table using a domain as it's field type. + + + + + typdefaultbin + text + + + typdefaultbin is NULL for types without a + default value. If it's not NULL, it contains the internal string + representation of the default expression node. + + + typdefault text diff --git a/doc/src/sgml/ref/allfiles.sgml b/doc/src/sgml/ref/allfiles.sgml index 3ea658fd042..460f150bc89 100644 --- a/doc/src/sgml/ref/allfiles.sgml +++ b/doc/src/sgml/ref/allfiles.sgml @@ -1,5 +1,5 @@ @@ -52,6 +52,7 @@ Complete list of usable sgml source files in this directory. + @@ -69,6 +70,7 @@ Complete list of usable sgml source files in this directory. + diff --git a/doc/src/sgml/ref/comment.sgml b/doc/src/sgml/ref/comment.sgml index 026533de954..f3530b71ce6 100644 --- a/doc/src/sgml/ref/comment.sgml +++ b/doc/src/sgml/ref/comment.sgml @@ -1,5 +1,5 @@ @@ -25,7 +25,7 @@ PostgreSQL documentation COMMENT ON [ - [ DATABASE | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ] object_name | + [ DATABASE | DOMAIN | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ] object_name | COLUMN table_name.column_name | AGGREGATE agg_name (agg_type) | FUNCTION func_name (arg1, arg2, ...) | @@ -33,7 +33,7 @@ COMMENT ON TRIGGER trigger_name ON table_name ] IS 'text' - + 1999-10-25 @@ -64,7 +64,7 @@ COMMENT ON - + 1998-09-08 @@ -99,7 +99,7 @@ COMMENT COMMENT stores a comment about a database object. - Comments can be + Comments can be easily retrieved with psql's \dd, \d+, or \l+ commands. Other user interfaces to retrieve comments can be built atop @@ -141,6 +141,7 @@ COMMENT ON mytable IS 'This is my table.'; COMMENT ON DATABASE my_database IS 'Development Database'; +COMMENT ON DOMAIN my_domain IS 'Email Address Domain'; COMMENT ON INDEX my_index IS 'Enforces uniqueness on employee id'; COMMENT ON RULE my_rule IS 'Logs UPDATES of employee records'; COMMENT ON SEQUENCE my_sequence IS 'Used to generate primary keys'; @@ -155,12 +156,12 @@ COMMENT ON TRIGGER my_trigger ON my_table IS 'Used for R.I.'; - + Compatibility - + 1998-09-08 diff --git a/doc/src/sgml/ref/create_domain.sgml b/doc/src/sgml/ref/create_domain.sgml new file mode 100644 index 00000000000..5f79dc63b53 --- /dev/null +++ b/doc/src/sgml/ref/create_domain.sgml @@ -0,0 +1,231 @@ + + + + + + CREATE DOMAIN + + SQL - Language Statements + + + + CREATE DOMAIN + + + define a new domain + + + + + 2002-02-24 + + +CREATE DOMAIN domainname data_type [ DEFAULT default_expr ] [ column_constraint [, ... ] ] +[ CONSTRAINT constraint_name ] +{ NOT NULL | NULL } + + + + + + 2002-02-24 + + + Parameters + + + + + + domainname + + + The name of a domain to be created. + + + + + + data_type + + + The data type of the domain. This may include array specifiers. + Refer to the User's Guide for further + information about data types and arrays. + + + + + + DEFAULT + default_expr + + + The DEFAULT clause assigns a default data value for + the column whose column definition it appears within. The value + is any variable-free expression (subselects and cross-references + to other columns in the current table are not allowed). The + data type of the default expression must match the data type of the + domain. + + + + The default expression will be used in any insert operation that + does not specify a value for the domain. If there is no default + for a domain, then the default is NULL. + + + + + The default of a column will be tested before that of the domain. + + + + + + + CONSTRAINT constraint_name + + + An optional name for a domain. If not specified, + the system generates a name. + + + + + + NOT NULL + + + The column is not allowed to contain NULL values. This is + equivalent to the column constraint CHECK (column NOT NULL). + + + + + + NULL + + + The column is allowed to contain NULL values. This is the default. + + + + This clause is only available for compatibility with + non-standard SQL databases. Its use is discouraged in new + applications. + + + + + + + + + + + 2002-02-24 + + + Outputs + + + + + + +CREATE DOMAIN + + + + Message returned if the domain is successfully created. + + + + + + + + + + + 2002-02-24 + + + Description + + + + CREATE DOMAIN allows the user to register a new user data + domain with PostgreSQL for use in the current data base. The + user who defines a domain becomes its owner. + domainname is + the name of the new type and must be unique within the + types and domains defined for this database. + + + + Domains are useful for abstracting common fields between tables into + a single location for maintenance. An email address column may be used + in several tables, all with the same properties. Define a domain and + use that rather than setting up each tables constraints individually. + + + + + Examples + + This example creates the country_code data type and then uses the + type in a table definition: + +CREATE DOMAIN country_code char(2) NOT NULL; +CREATE TABLE countrylist (id INT4, country country_code); + + + + + + Compatibility + + + This CREATE DOMAIN command is a + PostgreSQL extension. CHECK and FOREIGN KEY + constraints are currently unsupported. + + + + + See Also + + + + PostgreSQL Programmer's Guide + + + + + + + diff --git a/doc/src/sgml/ref/drop_domain.sgml b/doc/src/sgml/ref/drop_domain.sgml new file mode 100644 index 00000000000..e9bc38ad28c --- /dev/null +++ b/doc/src/sgml/ref/drop_domain.sgml @@ -0,0 +1,167 @@ + + + + + + DROP DOMAIN + + SQL - Language Statements + + + + DROP DOMAIN + + + remove a user-defined domain + + + + + 1999-07-20 + + +DROP DOMAIN domainname [, ...] + + + + + 2002-02-24 + + + Inputs + + + + + domainname + + + The name of an existing domain. + + + + + + + + + + 2002-02-24 + + + Outputs + + + + + +DROP + + + + The message returned if the command is successful. + + + + + +ERROR: RemoveDomain: type 'domainname' does not exist + + + + This message occurs if the specified domain (or type) is not found. + + + + + + + + + + + 2002-02-24 + + + Description + + + DROP DOMAIN will remove a user domain from the + system catalogs. + + + Only the owner of a domain can remove it. + + + + + Notes + + + + + It is the user's responsibility to remove any operators, + functions, aggregates, access methods, and tables that + use a deleted domain. + + + + + + + Examples + + To remove the box domain: + + +DROP DOMAIN box RESTRICT; + + + + + + Compatibility + + + A DROP DOMAIN statement exists in SQL99. As with + most other drop commands, DROP + DOMAIN in SQL99 requires a drop behavior + clause to select between dropping all dependent objects or refusing + to drop if dependent objects exist: + +DROP DOMAIN name { CASCADE | RESTRICT } + + PostgreSQL enforces the existance of + RESTRICT or CASCADE but ignores their enforcement against the + system tables. + + + + + See Also + + + + + + + + diff --git a/doc/src/sgml/reference.sgml b/doc/src/sgml/reference.sgml index 0ca0ea5a9c4..b6b63254462 100644 --- a/doc/src/sgml/reference.sgml +++ b/doc/src/sgml/reference.sgml @@ -1,5 +1,5 @@ @@ -61,6 +61,7 @@ PostgreSQL Reference Manual &createAggregate; &createConstraint; &createDatabase; + &createDomain; &createFunction; &createGroup; &createIndex; @@ -78,6 +79,7 @@ PostgreSQL Reference Manual &delete; &dropAggregate; &dropDatabase; + &dropDomain; &dropFunction; &dropGroup; &dropIndex; @@ -115,7 +117,7 @@ PostgreSQL Reference Manual &unlisten; &update; &vacuum; - +