Commit 11333426 authored by Tom Lane's avatar Tom Lane

Implement DROP SCHEMA. It lacks support for dropping conversions and

operator classes, both of which are schema-local and so should really
be droppable.
parent 8bed350c
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.39 2002/04/25 21:47:07 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.40 2002/07/18 16:47:22 tgl Exp $
PostgreSQL documentation PostgreSQL documentation
Complete list of usable sgml source files in this directory. Complete list of usable sgml source files in this directory.
--> -->
...@@ -79,6 +79,7 @@ Complete list of usable sgml source files in this directory. ...@@ -79,6 +79,7 @@ Complete list of usable sgml source files in this directory.
<!entity dropLanguage system "drop_language.sgml"> <!entity dropLanguage system "drop_language.sgml">
<!entity dropOperator system "drop_operator.sgml"> <!entity dropOperator system "drop_operator.sgml">
<!entity dropRule system "drop_rule.sgml"> <!entity dropRule system "drop_rule.sgml">
<!entity dropSchema system "drop_schema.sgml">
<!entity dropSequence system "drop_sequence.sgml"> <!entity dropSequence system "drop_sequence.sgml">
<!entity dropTable system "drop_table.sgml"> <!entity dropTable system "drop_table.sgml">
<!entity dropTrigger system "drop_trigger.sgml"> <!entity dropTrigger system "drop_trigger.sgml">
......
<!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_schema.sgml,v 1.1 2002/07/18 16:47:22 tgl Exp $
PostgreSQL documentation
-->
<refentry id="SQL-DROPSCHEMA">
<refmeta>
<refentrytitle id="SQL-DROPSCHEMA-TITLE">DROP SCHEMA</refentrytitle>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
</refmeta>
<refnamediv>
<refname>
DROP SCHEMA
</refname>
<refpurpose>
remove a schema
</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refsynopsisdivinfo>
<date>2002-07-18</date>
</refsynopsisdivinfo>
<synopsis>
DROP SCHEMA <replaceable class="PARAMETER">name</replaceable> [, ...] [ CASCADE | RESTRICT ]
</synopsis>
<refsect2 id="R2-SQL-DROPSCHEMA-1">
<refsect2info>
<date>2002-07-18</date>
</refsect2info>
<title>
Inputs
</title>
<para>
<variablelist>
<varlistentry>
<term><replaceable class="PARAMETER">name</replaceable></term>
<listitem>
<para>
The name of a schema.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>CASCADE</term>
<listitem>
<para>
Automatically drop objects (tables, functions, etc) that are contained
in the schema.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>RESTRICT</term>
<listitem>
<para>
Refuse to drop the schema if it contains any objects.
This is the default.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2>
<refsect2 id="R2-SQL-DROPSCHEMA-2">
<refsect2info>
<date>2002-07-18</date>
</refsect2info>
<title>
Outputs
</title>
<para>
<variablelist>
<varlistentry>
<term><computeroutput>
DROP SCHEMA
</computeroutput></term>
<listitem>
<para>
The message returned if the schema is successfully dropped.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><computeroutput>
ERROR: Schema "<replaceable class="parameter">name</replaceable>" does not exist
</computeroutput></term>
<listitem>
<para>
This message occurs if the specified schema does not exist.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect2>
</refsynopsisdiv>
<refsect1 id="R1-SQL-DROPSCHEMA-1">
<refsect1info>
<date>2002-07-18</date>
</refsect1info>
<title>
Description
</title>
<para>
<command>DROP SCHEMA</command> removes schemas from the data base.
</para>
<para>
A schema can only be dropped by its owner or a superuser. Note that
the owner can drop the schema (and thereby all contained objects)
even if he does not own some of the objects within the schema.
</para>
<refsect2 id="R2-SQL-DROPSCHEMA-3">
<refsect2info>
<date>2002-07-18</date>
</refsect2info>
<title>
Notes
</title>
<para>
Refer to the <command>CREATE SCHEMA</command> statement for
information on how to create a schema.
</para>
</refsect2>
</refsect1>
<refsect1 id="R1-SQL-DROPSCHEMA-2">
<title>
Usage
</title>
<para>
To remove schema <literal>mystuff</literal> from the database,
along with everything it contains:
<programlisting>
DROP SCHEMA mystuff CASCADE;
</programlisting>
</para>
</refsect1>
<refsect1 id="R1-SQL-DROPSCHEMA-3">
<title>
Compatibility
</title>
<refsect2 id="R2-SQL-DROPSCHEMA-4">
<refsect2info>
<date>2002-07-18</date>
</refsect2info>
<title>
SQL92
</title>
<para>
<command>DROP SCHEMA</command> is fully compatible with
<acronym>SQL92</acronym>, except that the standard only allows
one schema to be dropped per command.
</para>
</refsect2>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:nil
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../reference.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:"/usr/lib/sgml/catalog"
sgml-local-ecat-files:nil
End:
-->
<!-- reference.sgml <!-- reference.sgml
$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.28 2002/04/25 21:47:06 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.29 2002/07/18 16:47:22 tgl Exp $
PostgreSQL Reference Manual PostgreSQL Reference Manual
--> -->
...@@ -88,6 +88,7 @@ PostgreSQL Reference Manual ...@@ -88,6 +88,7 @@ PostgreSQL Reference Manual
&dropLanguage; &dropLanguage;
&dropOperator; &dropOperator;
&dropRule; &dropRule;
&dropSchema;
&dropSequence; &dropSequence;
&dropTable; &dropTable;
&dropTrigger; &dropTrigger;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.3 2002/07/16 05:53:33 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.4 2002/07/18 16:47:22 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -25,12 +25,14 @@ ...@@ -25,12 +25,14 @@
#include "catalog/pg_constraint.h" #include "catalog/pg_constraint.h"
#include "catalog/pg_depend.h" #include "catalog/pg_depend.h"
#include "catalog/pg_language.h" #include "catalog/pg_language.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_rewrite.h" #include "catalog/pg_rewrite.h"
#include "catalog/pg_trigger.h" #include "catalog/pg_trigger.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "commands/comment.h" #include "commands/comment.h"
#include "commands/defrem.h" #include "commands/defrem.h"
#include "commands/proclang.h" #include "commands/proclang.h"
#include "commands/schemacmds.h"
#include "commands/trigger.h" #include "commands/trigger.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#include "miscadmin.h" #include "miscadmin.h"
...@@ -54,6 +56,7 @@ typedef enum ObjectClasses ...@@ -54,6 +56,7 @@ typedef enum ObjectClasses
OCLASS_OPERATOR, /* pg_operator */ OCLASS_OPERATOR, /* pg_operator */
OCLASS_REWRITE, /* pg_rewrite */ OCLASS_REWRITE, /* pg_rewrite */
OCLASS_TRIGGER, /* pg_trigger */ OCLASS_TRIGGER, /* pg_trigger */
OCLASS_SCHEMA, /* pg_namespace */
MAX_OCLASS /* MUST BE LAST */ MAX_OCLASS /* MUST BE LAST */
} ObjectClasses; } ObjectClasses;
...@@ -597,6 +600,10 @@ doDeletion(const ObjectAddress *object) ...@@ -597,6 +600,10 @@ doDeletion(const ObjectAddress *object)
RemoveTriggerById(object->objectId); RemoveTriggerById(object->objectId);
break; break;
case OCLASS_SCHEMA:
RemoveSchemaById(object->objectId);
break;
default: default:
elog(ERROR, "doDeletion: Unsupported object class %u", elog(ERROR, "doDeletion: Unsupported object class %u",
object->classId); object->classId);
...@@ -981,6 +988,7 @@ init_object_classes(void) ...@@ -981,6 +988,7 @@ init_object_classes(void)
object_classes[OCLASS_OPERATOR] = get_system_catalog_relid(OperatorRelationName); object_classes[OCLASS_OPERATOR] = get_system_catalog_relid(OperatorRelationName);
object_classes[OCLASS_REWRITE] = get_system_catalog_relid(RewriteRelationName); object_classes[OCLASS_REWRITE] = get_system_catalog_relid(RewriteRelationName);
object_classes[OCLASS_TRIGGER] = get_system_catalog_relid(TriggerRelationName); object_classes[OCLASS_TRIGGER] = get_system_catalog_relid(TriggerRelationName);
object_classes[OCLASS_SCHEMA] = get_system_catalog_relid(NamespaceRelationName);
object_classes_initialized = true; object_classes_initialized = true;
} }
...@@ -1045,6 +1053,11 @@ getObjectClass(const ObjectAddress *object) ...@@ -1045,6 +1053,11 @@ getObjectClass(const ObjectAddress *object)
Assert(object->objectSubId == 0); Assert(object->objectSubId == 0);
return OCLASS_TRIGGER; return OCLASS_TRIGGER;
} }
if (object->classId == object_classes[OCLASS_SCHEMA])
{
Assert(object->objectSubId == 0);
return OCLASS_SCHEMA;
}
elog(ERROR, "getObjectClass: Unknown object class %u", elog(ERROR, "getObjectClass: Unknown object class %u",
object->classId); object->classId);
...@@ -1265,6 +1278,22 @@ getObjectDescription(const ObjectAddress *object) ...@@ -1265,6 +1278,22 @@ getObjectDescription(const ObjectAddress *object)
break; break;
} }
case OCLASS_SCHEMA:
{
HeapTuple schemaTup;
schemaTup = SearchSysCache(NAMESPACEOID,
ObjectIdGetDatum(object->objectId),
0, 0, 0);
if (!HeapTupleIsValid(schemaTup))
elog(ERROR, "getObjectDescription: Schema %u does not exist",
object->objectId);
appendStringInfo(&buffer, "schema %s",
NameStr(((Form_pg_namespace) GETSTRUCT(schemaTup))->nspname));
ReleaseSysCache(schemaTup);
break;
}
default: default:
appendStringInfo(&buffer, "unknown object %u %u %d", appendStringInfo(&buffer, "unknown object %u %u %d",
object->classId, object->classId,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.209 2002/07/16 22:12:18 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.210 2002/07/18 16:47:22 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -742,6 +742,25 @@ heap_create_with_catalog(const char *relname, ...@@ -742,6 +742,25 @@ heap_create_with_catalog(const char *relname,
AddNewAttributeTuples(new_rel_oid, new_rel_desc->rd_att, AddNewAttributeTuples(new_rel_oid, new_rel_desc->rd_att,
relhasoids, relkind); relhasoids, relkind);
/*
* make a dependency link to force the relation to be deleted if
* its namespace is. Skip this in bootstrap mode, since we don't
* make dependencies while bootstrapping.
*/
if (!IsBootstrapProcessingMode())
{
ObjectAddress myself,
referenced;
myself.classId = RelOid_pg_class;
myself.objectId = new_rel_oid;
myself.objectSubId = 0;
referenced.classId = get_system_catalog_relid(NamespaceRelationName);
referenced.objectId = relnamespace;
referenced.objectSubId = 0;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
}
/* /*
* store constraints and defaults passed in the tupdesc, if any. * store constraints and defaults passed in the tupdesc, if any.
* *
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.184 2002/07/16 05:53:33 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.185 2002/07/18 16:47:23 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -670,6 +670,9 @@ index_create(Oid heapRelationId, ...@@ -670,6 +670,9 @@ index_create(Oid heapRelationId,
* linked to the table. If it's not a CONSTRAINT, make the dependency * linked to the table. If it's not a CONSTRAINT, make the dependency
* directly on the table. * directly on the table.
* *
* We don't need a dependency on the namespace, because there'll be
* an indirect dependency via our parent table.
*
* During bootstrap we can't register any dependencies, and we don't * During bootstrap we can't register any dependencies, and we don't
* try to make a constraint either. * try to make a constraint either.
*/ */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.71 2002/07/16 22:12:18 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.72 2002/07/18 16:47:23 tgl Exp $
* *
* NOTES * NOTES
* these routines moved here from commands/define.c and somewhat cleaned up. * these routines moved here from commands/define.c and somewhat cleaned up.
...@@ -907,7 +907,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId) ...@@ -907,7 +907,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
* Create dependencies for a new operator (either a freshly inserted * Create dependencies for a new operator (either a freshly inserted
* complete operator, a new shell operator, or a just-updated shell). * complete operator, a new shell operator, or a just-updated shell).
* *
* NB: the OidIsValid tests in this routine are *all* necessary, in case * NB: the OidIsValid tests in this routine are necessary, in case
* the given operator is a shell. * the given operator is a shell.
*/ */
static void static void
...@@ -924,6 +924,15 @@ makeOperatorDependencies(HeapTuple tuple, Oid pg_operator_relid) ...@@ -924,6 +924,15 @@ makeOperatorDependencies(HeapTuple tuple, Oid pg_operator_relid)
/* In case we are updating a shell, delete any existing entries */ /* In case we are updating a shell, delete any existing entries */
deleteDependencyRecordsFor(myself.classId, myself.objectId); deleteDependencyRecordsFor(myself.classId, myself.objectId);
/* Dependency on namespace */
if (OidIsValid(oper->oprnamespace))
{
referenced.classId = get_system_catalog_relid(NamespaceRelationName);
referenced.objectId = oper->oprnamespace;
referenced.objectSubId = 0;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
}
/* Dependency on left type */ /* Dependency on left type */
if (OidIsValid(oper->oprleft)) if (OidIsValid(oper->oprleft))
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.77 2002/07/16 22:12:19 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.78 2002/07/18 16:47:23 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -268,6 +268,12 @@ ProcedureCreate(const char *procedureName, ...@@ -268,6 +268,12 @@ ProcedureCreate(const char *procedureName,
myself.objectId = retval; myself.objectId = retval;
myself.objectSubId = 0; myself.objectSubId = 0;
/* dependency on namespace */
referenced.classId = get_system_catalog_relid(NamespaceRelationName);
referenced.objectId = procNamespace;
referenced.objectSubId = 0;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
/* dependency on implementation language */ /* dependency on implementation language */
referenced.classId = get_system_catalog_relid(LanguageRelationName); referenced.classId = get_system_catalog_relid(LanguageRelationName);
referenced.objectId = languageObjectId; referenced.objectId = languageObjectId;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.73 2002/07/12 18:43:15 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.74 2002/07/18 16:47:23 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h" #include "utils/syscache.h"
...@@ -167,8 +168,6 @@ TypeCreate(const char *typeName, ...@@ -167,8 +168,6 @@ TypeCreate(const char *typeName,
NameData name; NameData name;
TupleDesc tupDesc; TupleDesc tupDesc;
int i; int i;
ObjectAddress myself,
referenced;
/* /*
* validate size specifications: either positive (fixed-length) or -1 * validate size specifications: either positive (fixed-length) or -1
...@@ -302,12 +301,27 @@ TypeCreate(const char *typeName, ...@@ -302,12 +301,27 @@ TypeCreate(const char *typeName,
} }
/* /*
* Create dependencies * Create dependencies. We can/must skip this in bootstrap mode.
*/ */
if (!IsBootstrapProcessingMode())
{
ObjectAddress myself,
referenced;
myself.classId = RelOid_pg_type; myself.classId = RelOid_pg_type;
myself.objectId = typeObjectId; myself.objectId = typeObjectId;
myself.objectSubId = 0; myself.objectSubId = 0;
/* dependency on namespace */
/* skip for relation rowtype, since we have indirect dependency */
if (!OidIsValid(relationOid))
{
referenced.classId = get_system_catalog_relid(NamespaceRelationName);
referenced.objectId = typeNamespace;
referenced.objectSubId = 0;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
}
/* Normal dependencies on the I/O functions */ /* Normal dependencies on the I/O functions */
referenced.classId = RelOid_pg_proc; referenced.classId = RelOid_pg_proc;
referenced.objectId = inputProcedure; referenced.objectId = inputProcedure;
...@@ -349,11 +363,11 @@ TypeCreate(const char *typeName, ...@@ -349,11 +363,11 @@ TypeCreate(const char *typeName,
} }
/* /*
* If the type is an array type, mark it auto-dependent on the * If the type is an array type, mark it auto-dependent on the base
* base type. (This is a compromise between the typical case where the * type. (This is a compromise between the typical case where the
* array type is automatically generated and the case where it is manually * array type is automatically generated and the case where it is
* created: we'd prefer INTERNAL for the former case and NORMAL for the * manually created: we'd prefer INTERNAL for the former case and
* latter.) * NORMAL for the latter.)
*/ */
if (OidIsValid(elementType)) if (OidIsValid(elementType))
{ {
...@@ -371,6 +385,7 @@ TypeCreate(const char *typeName, ...@@ -371,6 +385,7 @@ TypeCreate(const char *typeName,
referenced.objectSubId = 0; referenced.objectSubId = 0;
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
} }
}
/* /*
* finish up * finish up
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* schemacmds.c * schemacmds.c
* schema creation command support code * schema creation/manipulation commands
* *
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v 1.4 2002/06/11 13:40:50 wieck Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v 1.5 2002/07/18 16:47:24 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
#include "access/heapam.h"
#include "catalog/catalog.h" #include "catalog/catalog.h"
#include "catalog/catname.h"
#include "catalog/dependency.h"
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "catalog/pg_namespace.h" #include "catalog/pg_namespace.h"
#include "commands/schemacmds.h" #include "commands/schemacmds.h"
...@@ -23,6 +26,7 @@ ...@@ -23,6 +26,7 @@
#include "tcop/utility.h" #include "tcop/utility.h"
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/syscache.h"
/* /*
...@@ -139,3 +143,70 @@ CreateSchemaCommand(CreateSchemaStmt *stmt) ...@@ -139,3 +143,70 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
/* Reset current user */ /* Reset current user */
SetUserId(saved_userid); SetUserId(saved_userid);
} }
/*
* RemoveSchema
* Removes a schema.
*/
void
RemoveSchema(List *names, DropBehavior behavior)
{
char *namespaceName;
Oid namespaceId;
ObjectAddress object;
if (length(names) != 1)
elog(ERROR, "Schema name may not be qualified");
namespaceName = strVal(lfirst(names));
namespaceId = GetSysCacheOid(NAMESPACENAME,
CStringGetDatum(namespaceName),
0, 0, 0);
if (!OidIsValid(namespaceId))
elog(ERROR, "Schema \"%s\" does not exist", namespaceName);
/* Permission check */
if (!pg_namespace_ownercheck(namespaceId, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, namespaceName);
/*
* Do the deletion. Objects contained in the schema are removed
* by means of their dependency links to the schema.
*
* XXX currently, index opclasses don't have creation/deletion
* commands, so they will not get removed when the containing
* schema is removed. This is annoying but not fatal.
*/
object.classId = get_system_catalog_relid(NamespaceRelationName);
object.objectId = namespaceId;
object.objectSubId = 0;
performDeletion(&object, behavior);
}
/*
* Guts of schema deletion.
*/
void
RemoveSchemaById(Oid schemaOid)
{
Relation relation;
HeapTuple tup;
relation = heap_openr(NamespaceRelationName, RowExclusiveLock);
tup = SearchSysCache(NAMESPACEOID,
ObjectIdGetDatum(schemaOid),
0, 0, 0);
if (!HeapTupleIsValid(tup))
elog(ERROR, "RemoveSchemaById: schema %u not found",
schemaOid);
simple_heap_delete(relation, &tup->t_self);
ReleaseSysCache(tup);
heap_close(relation, RowExclusiveLock);
}
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.344 2002/07/18 04:43:50 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.345 2002/07/18 16:47:24 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -132,7 +132,7 @@ static void doNegateFloat(Value *v); ...@@ -132,7 +132,7 @@ static void doNegateFloat(Value *v);
} }
%type <node> stmt, schema_stmt, %type <node> stmt, schema_stmt,
AlterDatabaseSetStmt, AlterGroupStmt, AlterSchemaStmt, AlterDatabaseSetStmt, AlterGroupStmt,
AlterTableStmt, AlterUserStmt, AlterUserSetStmt, AlterTableStmt, AlterUserStmt, AlterUserSetStmt,
AnalyzeStmt, ClosePortalStmt, ClusterStmt, CommentStmt, AnalyzeStmt, ClosePortalStmt, ClusterStmt, CommentStmt,
ConstraintsSetStmt, CopyStmt, CreateAsStmt, ConstraintsSetStmt, CopyStmt, CreateAsStmt,
...@@ -140,7 +140,7 @@ static void doNegateFloat(Value *v); ...@@ -140,7 +140,7 @@ static void doNegateFloat(Value *v);
CreateSchemaStmt, CreateSeqStmt, CreateStmt, CreateSchemaStmt, CreateSeqStmt, CreateStmt,
CreateAssertStmt, CreateTrigStmt, CreateUserStmt, CreateAssertStmt, CreateTrigStmt, CreateUserStmt,
CreatedbStmt, CursorStmt, DefineStmt, DeleteStmt, CreatedbStmt, CursorStmt, DefineStmt, DeleteStmt,
DropGroupStmt, DropPLangStmt, DropSchemaStmt, DropStmt, DropGroupStmt, DropPLangStmt, DropStmt,
DropAssertStmt, DropTrigStmt, DropRuleStmt, DropAssertStmt, DropTrigStmt, DropRuleStmt,
DropUserStmt, DropdbStmt, ExplainStmt, FetchStmt, DropUserStmt, DropdbStmt, ExplainStmt, FetchStmt,
GrantStmt, IndexStmt, InsertStmt, ListenStmt, LoadStmt, GrantStmt, IndexStmt, InsertStmt, ListenStmt, LoadStmt,
...@@ -468,7 +468,6 @@ stmtmulti: stmtmulti ';' stmt ...@@ -468,7 +468,6 @@ stmtmulti: stmtmulti ';' stmt
stmt : stmt :
AlterDatabaseSetStmt AlterDatabaseSetStmt
| AlterGroupStmt | AlterGroupStmt
| AlterSchemaStmt
| AlterTableStmt | AlterTableStmt
| AlterUserStmt | AlterUserStmt
| AlterUserSetStmt | AlterUserSetStmt
...@@ -488,7 +487,6 @@ stmt : ...@@ -488,7 +487,6 @@ stmt :
| ClusterStmt | ClusterStmt
| DefineStmt | DefineStmt
| DropStmt | DropStmt
| DropSchemaStmt
| TruncateStmt | TruncateStmt
| CommentStmt | CommentStmt
| DropGroupStmt | DropGroupStmt
...@@ -746,7 +744,6 @@ DropGroupStmt: ...@@ -746,7 +744,6 @@ DropGroupStmt:
* *
* Manipulate a schema * Manipulate a schema
* *
*
*****************************************************************************/ *****************************************************************************/
CreateSchemaStmt: CreateSchemaStmt:
...@@ -773,20 +770,6 @@ CreateSchemaStmt: ...@@ -773,20 +770,6 @@ CreateSchemaStmt:
} }
; ;
AlterSchemaStmt:
ALTER SCHEMA ColId
{
elog(ERROR, "ALTER SCHEMA not yet supported");
}
;
DropSchemaStmt:
DROP SCHEMA ColId opt_drop_behavior
{
elog(ERROR, "DROP SCHEMA not yet supported");
}
;
OptSchemaName: OptSchemaName:
ColId { $$ = $1; } ColId { $$ = $1; }
| /* EMPTY */ { $$ = NULL; } | /* EMPTY */ { $$ = NULL; }
...@@ -2306,6 +2289,7 @@ drop_type: TABLE { $$ = DROP_TABLE; } ...@@ -2306,6 +2289,7 @@ drop_type: TABLE { $$ = DROP_TABLE; }
| TYPE_P { $$ = DROP_TYPE; } | TYPE_P { $$ = DROP_TYPE; }
| DOMAIN_P { $$ = DROP_DOMAIN; } | DOMAIN_P { $$ = DROP_DOMAIN; }
| CONVERSION_P { $$ = DROP_CONVERSION; } | CONVERSION_P { $$ = DROP_CONVERSION; }
| SCHEMA { $$ = DROP_SCHEMA; }
; ;
any_name_list: any_name_list:
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.270 2002/07/13 01:02:14 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.271 2002/07/18 16:47:25 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -1693,7 +1693,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -1693,7 +1693,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.270 $ $Date: 2002/07/13 01:02:14 $\n"); puts("$Revision: 1.271 $ $Date: 2002/07/18 16:47:25 $\n");
} }
/* /*
...@@ -2220,7 +2220,10 @@ CreateCommandTag(Node *parsetree) ...@@ -2220,7 +2220,10 @@ CreateCommandTag(Node *parsetree)
tag = "DROP DOMAIN"; tag = "DROP DOMAIN";
break; break;
case DROP_CONVERSION: case DROP_CONVERSION:
tag = "DROP CONVERSON"; tag = "DROP CONVERSION";
break;
case DROP_SCHEMA:
tag = "DROP SCHEMA";
break; break;
default: default:
tag = "???"; tag = "???";
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.162 2002/07/12 18:43:17 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.163 2002/07/18 16:47:25 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -252,11 +252,7 @@ ProcessUtility(Node *parsetree, ...@@ -252,11 +252,7 @@ ProcessUtility(Node *parsetree,
* relation and attribute manipulation * relation and attribute manipulation
*/ */
case T_CreateSchemaStmt: case T_CreateSchemaStmt:
{ CreateSchemaCommand((CreateSchemaStmt *) parsetree);
CreateSchemaStmt *stmt = (CreateSchemaStmt *) parsetree;
CreateSchemaCommand(stmt);
}
break; break;
case T_CreateStmt: case T_CreateStmt:
...@@ -322,17 +318,20 @@ ProcessUtility(Node *parsetree, ...@@ -322,17 +318,20 @@ ProcessUtility(Node *parsetree,
break; break;
case DROP_CONVERSION: case DROP_CONVERSION:
/* RemoveDomain does its own permissions checks */ /* does its own permissions checks */
DropConversionCommand(names); DropConversionCommand(names);
break; break;
case DROP_SCHEMA:
/* RemoveSchema does its own permissions checks */
RemoveSchema(names, stmt->behavior);
break;
} }
/* /*
* Make sure subsequent loop iterations will see * We used to need to do CommandCounterIncrement()
* results of this one; needed if removing multiple * here, but now it's done inside performDeletion().
* rules for same table, for example.
*/ */
CommandCounterIncrement();
} }
} }
break; break;
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.159 2002/07/18 02:02:30 ishii Exp $ # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.160 2002/07/18 16:47:25 tgl Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -717,6 +717,9 @@ INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_language; ...@@ -717,6 +717,9 @@ INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_language;
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_operator; INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_operator;
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_rewrite; INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_rewrite;
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_trigger; INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_trigger;
-- restriction here to avoid pinning the public namespace
INSERT INTO pg_depend SELECT 0,0,0, tableoid,oid,0, 'p' FROM pg_namespace \
WHERE nspname LIKE 'pg%';
EOF EOF
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
exit_nicely exit_nicely
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: schemacmds.h,v 1.1 2002/04/15 05:22:04 tgl Exp $ * $Id: schemacmds.h,v 1.2 2002/07/18 16:47:26 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -19,4 +19,7 @@ ...@@ -19,4 +19,7 @@
extern void CreateSchemaCommand(CreateSchemaStmt *parsetree); extern void CreateSchemaCommand(CreateSchemaStmt *parsetree);
extern void RemoveSchema(List *names, DropBehavior behavior);
extern void RemoveSchemaById(Oid schemaOid);
#endif /* SCHEMACMDS_H */ #endif /* SCHEMACMDS_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: parsenodes.h,v 1.190 2002/07/18 04:43:51 momjian Exp $ * $Id: parsenodes.h,v 1.191 2002/07/18 16:47:26 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1136,7 +1136,7 @@ typedef struct CreateDomainStmt ...@@ -1136,7 +1136,7 @@ typedef struct CreateDomainStmt
} CreateDomainStmt; } CreateDomainStmt;
/* ---------------------- /* ----------------------
* Drop Table|Sequence|View|Index|Type|Domain Statement * Drop Table|Sequence|View|Index|Type|Domain|Conversion|Schema Statement
* ---------------------- * ----------------------
*/ */
...@@ -1147,6 +1147,7 @@ typedef struct CreateDomainStmt ...@@ -1147,6 +1147,7 @@ typedef struct CreateDomainStmt
#define DROP_TYPE 5 #define DROP_TYPE 5
#define DROP_DOMAIN 6 #define DROP_DOMAIN 6
#define DROP_CONVERSION 7 #define DROP_CONVERSION 7
#define DROP_SCHEMA 8
typedef struct DropStmt typedef struct DropStmt
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment