Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1133342

Browse files
committed
Implement DROP SCHEMA. It lacks support for dropping conversions and
operator classes, both of which are schema-local and so should reallybe droppable.
1 parent8bed350 commit1133342

File tree

16 files changed

+438
-107
lines changed

16 files changed

+438
-107
lines changed

‎doc/src/sgml/ref/allfiles.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.39 2002/04/25 21:47:07 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.40 2002/07/18 16:47:22 tgl Exp $
33
PostgreSQL documentation
44
Complete list of usable sgml source files in this directory.
55
-->
@@ -79,6 +79,7 @@ Complete list of usable sgml source files in this directory.
7979
<!entity dropLanguage system "drop_language.sgml">
8080
<!entity dropOperator system "drop_operator.sgml">
8181
<!entity dropRule system "drop_rule.sgml">
82+
<!entity dropSchema system "drop_schema.sgml">
8283
<!entity dropSequence system "drop_sequence.sgml">
8384
<!entity dropTable system "drop_table.sgml">
8485
<!entity dropTrigger system "drop_trigger.sgml">

‎doc/src/sgml/ref/drop_schema.sgml

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
<!--
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/drop_schema.sgml,v 1.1 2002/07/18 16:47:22 tgl Exp $
3+
PostgreSQL documentation
4+
-->
5+
6+
<refentry id="SQL-DROPSCHEMA">
7+
<refmeta>
8+
<refentrytitle id="SQL-DROPSCHEMA-TITLE">DROP SCHEMA</refentrytitle>
9+
<refmiscinfo>SQL - Language Statements</refmiscinfo>
10+
</refmeta>
11+
<refnamediv>
12+
<refname>
13+
DROP SCHEMA
14+
</refname>
15+
<refpurpose>
16+
remove a schema
17+
</refpurpose>
18+
</refnamediv>
19+
<refsynopsisdiv>
20+
<refsynopsisdivinfo>
21+
<date>2002-07-18</date>
22+
</refsynopsisdivinfo>
23+
<synopsis>
24+
DROP SCHEMA <replaceable class="PARAMETER">name</replaceable> [, ...] [ CASCADE | RESTRICT ]
25+
26+
</synopsis>
27+
28+
<refsect2 id="R2-SQL-DROPSCHEMA-1">
29+
<refsect2info>
30+
<date>2002-07-18</date>
31+
</refsect2info>
32+
<title>
33+
Inputs
34+
</title>
35+
<para>
36+
<variablelist>
37+
<varlistentry>
38+
<term><replaceable class="PARAMETER">name</replaceable></term>
39+
<listitem>
40+
<para>
41+
The name of a schema.
42+
</para>
43+
</listitem>
44+
</varlistentry>
45+
<varlistentry>
46+
<term>CASCADE</term>
47+
<listitem>
48+
<para>
49+
Automatically drop objects (tables, functions, etc) that are contained
50+
in the schema.
51+
</para>
52+
</listitem>
53+
</varlistentry>
54+
<varlistentry>
55+
<term>RESTRICT</term>
56+
<listitem>
57+
<para>
58+
Refuse to drop the schema if it contains any objects.
59+
This is the default.
60+
</para>
61+
</listitem>
62+
</varlistentry>
63+
</variablelist>
64+
</para>
65+
</refsect2>
66+
67+
<refsect2 id="R2-SQL-DROPSCHEMA-2">
68+
<refsect2info>
69+
<date>2002-07-18</date>
70+
</refsect2info>
71+
<title>
72+
Outputs
73+
</title>
74+
<para>
75+
76+
<variablelist>
77+
<varlistentry>
78+
<term><computeroutput>
79+
DROP SCHEMA
80+
</computeroutput></term>
81+
<listitem>
82+
<para>
83+
The message returned if the schema is successfully dropped.
84+
</para>
85+
</listitem>
86+
</varlistentry>
87+
<varlistentry>
88+
<term><computeroutput>
89+
ERROR: Schema "<replaceable class="parameter">name</replaceable>" does not exist
90+
</computeroutput></term>
91+
<listitem>
92+
<para>
93+
This message occurs if the specified schema does not exist.
94+
</para>
95+
</listitem>
96+
</varlistentry>
97+
</variablelist>
98+
99+
</para>
100+
</refsect2>
101+
</refsynopsisdiv>
102+
103+
<refsect1 id="R1-SQL-DROPSCHEMA-1">
104+
<refsect1info>
105+
<date>2002-07-18</date>
106+
</refsect1info>
107+
<title>
108+
Description
109+
</title>
110+
<para>
111+
<command>DROP SCHEMA</command> removes schemas from the data base.
112+
</para>
113+
114+
<para>
115+
A schema can only be dropped by its owner or a superuser. Note that
116+
the owner can drop the schema (and thereby all contained objects)
117+
even if he does not own some of the objects within the schema.
118+
</para>
119+
120+
<refsect2 id="R2-SQL-DROPSCHEMA-3">
121+
<refsect2info>
122+
<date>2002-07-18</date>
123+
</refsect2info>
124+
<title>
125+
Notes
126+
</title>
127+
<para>
128+
Refer to the <command>CREATE SCHEMA</command> statement for
129+
information on how to create a schema.
130+
</para>
131+
</refsect2>
132+
</refsect1>
133+
134+
<refsect1 id="R1-SQL-DROPSCHEMA-2">
135+
<title>
136+
Usage
137+
</title>
138+
<para>
139+
To remove schema <literal>mystuff</literal> from the database,
140+
along with everything it contains:
141+
142+
<programlisting>
143+
DROP SCHEMA mystuff CASCADE;
144+
</programlisting>
145+
</para>
146+
</refsect1>
147+
148+
<refsect1 id="R1-SQL-DROPSCHEMA-3">
149+
<title>
150+
Compatibility
151+
</title>
152+
153+
<refsect2 id="R2-SQL-DROPSCHEMA-4">
154+
<refsect2info>
155+
<date>2002-07-18</date>
156+
</refsect2info>
157+
<title>
158+
SQL92
159+
</title>
160+
<para>
161+
<command>DROP SCHEMA</command> is fully compatible with
162+
<acronym>SQL92</acronym>, except that the standard only allows
163+
one schema to be dropped per command.
164+
</para>
165+
</refsect2>
166+
</refsect1>
167+
</refentry>
168+
169+
<!-- Keep this comment at the end of the file
170+
Local variables:
171+
mode: sgml
172+
sgml-omittag:nil
173+
sgml-shorttag:t
174+
sgml-minimize-attributes:nil
175+
sgml-always-quote-attributes:t
176+
sgml-indent-step:1
177+
sgml-indent-data:t
178+
sgml-parent-document:nil
179+
sgml-default-dtd-file:"../reference.ced"
180+
sgml-exposed-tags:nil
181+
sgml-local-catalogs:"/usr/lib/sgml/catalog"
182+
sgml-local-ecat-files:nil
183+
End:
184+
-->

‎doc/src/sgml/reference.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!-- reference.sgml
2-
$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.28 2002/04/25 21:47:06 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.29 2002/07/18 16:47:22 tgl Exp $
33

44
PostgreSQL Reference Manual
55
-->
@@ -88,6 +88,7 @@ PostgreSQL Reference Manual
8888
&dropLanguage;
8989
&dropOperator;
9090
&dropRule;
91+
&dropSchema;
9192
&dropSequence;
9293
&dropTable;
9394
&dropTrigger;

‎src/backend/catalog/dependency.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.3 2002/07/16 05:53:33 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/dependency.c,v 1.4 2002/07/18 16:47:22 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -25,12 +25,14 @@
2525
#include"catalog/pg_constraint.h"
2626
#include"catalog/pg_depend.h"
2727
#include"catalog/pg_language.h"
28+
#include"catalog/pg_namespace.h"
2829
#include"catalog/pg_rewrite.h"
2930
#include"catalog/pg_trigger.h"
3031
#include"catalog/pg_type.h"
3132
#include"commands/comment.h"
3233
#include"commands/defrem.h"
3334
#include"commands/proclang.h"
35+
#include"commands/schemacmds.h"
3436
#include"commands/trigger.h"
3537
#include"lib/stringinfo.h"
3638
#include"miscadmin.h"
@@ -54,6 +56,7 @@ typedef enum ObjectClasses
5456
OCLASS_OPERATOR,/* pg_operator */
5557
OCLASS_REWRITE,/* pg_rewrite */
5658
OCLASS_TRIGGER,/* pg_trigger */
59+
OCLASS_SCHEMA,/* pg_namespace */
5760
MAX_OCLASS/* MUST BE LAST */
5861
}ObjectClasses;
5962

@@ -597,6 +600,10 @@ doDeletion(const ObjectAddress *object)
597600
RemoveTriggerById(object->objectId);
598601
break;
599602

603+
caseOCLASS_SCHEMA:
604+
RemoveSchemaById(object->objectId);
605+
break;
606+
600607
default:
601608
elog(ERROR,"doDeletion: Unsupported object class %u",
602609
object->classId);
@@ -981,6 +988,7 @@ init_object_classes(void)
981988
object_classes[OCLASS_OPERATOR]=get_system_catalog_relid(OperatorRelationName);
982989
object_classes[OCLASS_REWRITE]=get_system_catalog_relid(RewriteRelationName);
983990
object_classes[OCLASS_TRIGGER]=get_system_catalog_relid(TriggerRelationName);
991+
object_classes[OCLASS_SCHEMA]=get_system_catalog_relid(NamespaceRelationName);
984992
object_classes_initialized= true;
985993
}
986994

@@ -1045,6 +1053,11 @@ getObjectClass(const ObjectAddress *object)
10451053
Assert(object->objectSubId==0);
10461054
returnOCLASS_TRIGGER;
10471055
}
1056+
if (object->classId==object_classes[OCLASS_SCHEMA])
1057+
{
1058+
Assert(object->objectSubId==0);
1059+
returnOCLASS_SCHEMA;
1060+
}
10481061

10491062
elog(ERROR,"getObjectClass: Unknown object class %u",
10501063
object->classId);
@@ -1265,6 +1278,22 @@ getObjectDescription(const ObjectAddress *object)
12651278
break;
12661279
}
12671280

1281+
caseOCLASS_SCHEMA:
1282+
{
1283+
HeapTupleschemaTup;
1284+
1285+
schemaTup=SearchSysCache(NAMESPACEOID,
1286+
ObjectIdGetDatum(object->objectId),
1287+
0,0,0);
1288+
if (!HeapTupleIsValid(schemaTup))
1289+
elog(ERROR,"getObjectDescription: Schema %u does not exist",
1290+
object->objectId);
1291+
appendStringInfo(&buffer,"schema %s",
1292+
NameStr(((Form_pg_namespace)GETSTRUCT(schemaTup))->nspname));
1293+
ReleaseSysCache(schemaTup);
1294+
break;
1295+
}
1296+
12681297
default:
12691298
appendStringInfo(&buffer,"unknown object %u %u %d",
12701299
object->classId,

‎src/backend/catalog/heap.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.209 2002/07/16 22:12:18 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.210 2002/07/18 16:47:22 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -742,6 +742,25 @@ heap_create_with_catalog(const char *relname,
742742
AddNewAttributeTuples(new_rel_oid,new_rel_desc->rd_att,
743743
relhasoids,relkind);
744744

745+
/*
746+
* make a dependency link to force the relation to be deleted if
747+
* its namespace is. Skip this in bootstrap mode, since we don't
748+
* make dependencies while bootstrapping.
749+
*/
750+
if (!IsBootstrapProcessingMode())
751+
{
752+
ObjectAddressmyself,
753+
referenced;
754+
755+
myself.classId=RelOid_pg_class;
756+
myself.objectId=new_rel_oid;
757+
myself.objectSubId=0;
758+
referenced.classId=get_system_catalog_relid(NamespaceRelationName);
759+
referenced.objectId=relnamespace;
760+
referenced.objectSubId=0;
761+
recordDependencyOn(&myself,&referenced,DEPENDENCY_NORMAL);
762+
}
763+
745764
/*
746765
* store constraints and defaults passed in the tupdesc, if any.
747766
*

‎src/backend/catalog/index.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.184 2002/07/16 05:53:33 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.185 2002/07/18 16:47:23 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -670,6 +670,9 @@ index_create(Oid heapRelationId,
670670
* linked to the table. If it's not a CONSTRAINT, make the dependency
671671
* directly on the table.
672672
*
673+
* We don't need a dependency on the namespace, because there'll be
674+
* an indirect dependency via our parent table.
675+
*
673676
* During bootstrap we can't register any dependencies, and we don't
674677
* try to make a constraint either.
675678
*/

‎src/backend/catalog/pg_operator.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.71 2002/07/16 22:12:18 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_operator.c,v 1.72 2002/07/18 16:47:23 tgl Exp $
1212
*
1313
* NOTES
1414
* these routines moved here from commands/define.c and somewhat cleaned up.
@@ -907,7 +907,7 @@ OperatorUpd(Oid baseId, Oid commId, Oid negId)
907907
* Create dependencies for a new operator (either a freshly inserted
908908
* complete operator, a new shell operator, or a just-updated shell).
909909
*
910-
* NB: the OidIsValid tests in this routine are*all*necessary, in case
910+
* NB: the OidIsValid tests in this routine are necessary, in case
911911
* the given operator is a shell.
912912
*/
913913
staticvoid
@@ -924,6 +924,15 @@ makeOperatorDependencies(HeapTuple tuple, Oid pg_operator_relid)
924924
/* In case we are updating a shell, delete any existing entries */
925925
deleteDependencyRecordsFor(myself.classId,myself.objectId);
926926

927+
/* Dependency on namespace */
928+
if (OidIsValid(oper->oprnamespace))
929+
{
930+
referenced.classId=get_system_catalog_relid(NamespaceRelationName);
931+
referenced.objectId=oper->oprnamespace;
932+
referenced.objectSubId=0;
933+
recordDependencyOn(&myself,&referenced,DEPENDENCY_NORMAL);
934+
}
935+
927936
/* Dependency on left type */
928937
if (OidIsValid(oper->oprleft))
929938
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp