diff options
author | Bruce Momjian | 2002-03-06 20:35:02 +0000 |
---|---|---|
committer | Bruce Momjian | 2002-03-06 20:35:02 +0000 |
commit | 01c76f7411c24b11e4ab36a9fe5f5017dc33be78 (patch) | |
tree | 279d40bc7e04a02e9cd9124ff0f21a79deb50e90 /src/backend/commands/remove.c | |
parent | 3d9f865e94b2e7b926ef083dd555ecc7d33bccf9 (diff) |
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/remove.c')
-rw-r--r-- | src/backend/commands/remove.c | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/src/backend/commands/remove.c b/src/backend/commands/remove.c index a0456adeb93..69e6e1b9000 100644 --- a/src/backend/commands/remove.c +++ b/src/backend/commands/remove.c @@ -1,14 +1,14 @@ /*------------------------------------------------------------------------- * * remove.c - * POSTGRES remove (function | type | operator ) utilty code. + * POSTGRES remove (domain | function | type | operator ) utilty code. * * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.66 2002/03/06 06:09:35 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.67 2002/03/06 20:34:47 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -22,6 +22,7 @@ #include "commands/comment.h" #include "commands/defrem.h" #include "miscadmin.h" +#include "parser/parse.h" #include "parser/parse_agg.h" #include "parser/parse_expr.h" #include "parser/parse_func.h" @@ -276,6 +277,60 @@ RemoveType(char *typeName) /* type name to be removed */ } /* + * RemoveDomain + * Removes the domain 'typeName' and all attributes and relations that + * use it. + */ +void +RemoveDomain(char *domainName, int behavior) /* domain name to be removed */ +{ + Relation relation; + HeapTuple tup; + TupleDesc description; + char typtype; + bool isnull; + + + /* Domains are stored as types. Check for permissions on the type */ + if (!pg_ownercheck(GetUserId(), domainName, TYPENAME)) + elog(ERROR, "RemoveDomain: type '%s': permission denied", + domainName); + + + relation = heap_openr(TypeRelationName, RowExclusiveLock); + description = RelationGetDescr(relation); + + tup = SearchSysCache(TYPENAME, + PointerGetDatum(domainName), + 0, 0, 0); + if (!HeapTupleIsValid(tup)) + elog(ERROR, "RemoveType: type '%s' does not exist", domainName); + + + /* Check that this is actually a domain */ + typtype = DatumGetChar(heap_getattr(tup, Anum_pg_type_typtype, description, &isnull)); + Assert(!isnull); + + if (typtype != 'd') { + elog(ERROR, "%s is not a domain", domainName); + } + + /* CASCADE unsupported */ + if (behavior == CASCADE) { + elog(ERROR, "DROP DOMAIN does not support the CASCADE keyword"); + } + + /* Delete any comments associated with this type */ + DeleteComments(tup->t_data->t_oid, RelationGetRelid(relation)); + + simple_heap_delete(relation, &tup->t_self); + + ReleaseSysCache(tup); + + heap_close(relation, RowExclusiveLock); +} + +/* * RemoveFunction * Deletes a function. * |