diff options
author | Robert Haas <rhaas@postgresql.org> | 2011-10-19 23:25:20 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2011-10-19 23:27:19 -0400 |
commit | 82a4a777d94bec965ab2f1d04b6e6a3f0447b377 (patch) | |
tree | b3560173b695b8391ca81edf47c4b364005a608b /src/backend/commands/typecmds.c | |
parent | 3301c83536e9da1e573e24ded2e610062dbf9cdc (diff) | |
download | postgresql-82a4a777d94bec965ab2f1d04b6e6a3f0447b377.tar.gz postgresql-82a4a777d94bec965ab2f1d04b6e6a3f0447b377.zip |
Consolidate DROP handling for some object types.
This gets rid of a significant amount of duplicative code.
KaiGai Kohei, reviewed in earlier versions by Dimitri Fontaine, with
further review and cleanup by me.
Diffstat (limited to 'src/backend/commands/typecmds.c')
-rw-r--r-- | src/backend/commands/typecmds.c | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 7c27f85cdc6..5069c5759ec 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -618,98 +618,6 @@ DefineType(List *names, List *parameters) pfree(array_type); } - -/* - * RemoveTypes - * Implements DROP TYPE and DROP DOMAIN - * - * Note: if DOMAIN is specified, we enforce that each type is a domain, but - * we don't enforce the converse for DROP TYPE - */ -void -RemoveTypes(DropStmt *drop) -{ - ObjectAddresses *objects; - ListCell *cell; - - /* - * First we identify all the types, then we delete them in a single - * performMultipleDeletions() call. This is to avoid unwanted DROP - * RESTRICT errors if one of the types depends on another. - */ - objects = new_object_addresses(); - - foreach(cell, drop->objects) - { - List *names = (List *) lfirst(cell); - TypeName *typename; - Oid typeoid; - HeapTuple tup; - ObjectAddress object; - Form_pg_type typ; - - /* Make a TypeName so we can use standard type lookup machinery */ - typename = makeTypeNameFromNameList(names); - - /* Use LookupTypeName here so that shell types can be removed. */ - tup = LookupTypeName(NULL, typename, NULL); - if (tup == NULL) - { - if (!drop->missing_ok) - { - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_OBJECT), - errmsg("type \"%s\" does not exist", - TypeNameToString(typename)))); - } - else - { - ereport(NOTICE, - (errmsg("type \"%s\" does not exist, skipping", - TypeNameToString(typename)))); - } - continue; - } - - typeoid = typeTypeId(tup); - typ = (Form_pg_type) GETSTRUCT(tup); - - /* Permission check: must own type or its namespace */ - if (!pg_type_ownercheck(typeoid, GetUserId()) && - !pg_namespace_ownercheck(typ->typnamespace, GetUserId())) - aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TYPE, - format_type_be(typeoid)); - - if (drop->removeType == OBJECT_DOMAIN) - { - /* Check that this is actually a domain */ - if (typ->typtype != TYPTYPE_DOMAIN) - ereport(ERROR, - (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("\"%s\" is not a domain", - TypeNameToString(typename)))); - } - - /* - * Note: we need no special check for array types here, as the normal - * treatment of internal dependencies handles it just fine - */ - - object.classId = TypeRelationId; - object.objectId = typeoid; - object.objectSubId = 0; - - add_exact_object_address(&object, objects); - - ReleaseSysCache(tup); - } - - performMultipleDeletions(objects, drop->behavior); - - free_object_addresses(objects); -} - - /* * Guts of type deletion. */ |