Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4997878

Browse files
committed
Doc: clarify that DROP ... CASCADE is recursive.
Apparently that's not obvious to everybody, so let's belabor the point. In passing, document that DROP POLICY has CASCADE/RESTRICT options (which it does, per gram.y) but they do nothing (I assume, anyway). Also update some long-obsolete commentary in gram.y. Discussion: <20160805104837.1412.84915@wrigleys.postgresql.org>
1 parent 4b234fd commit 4997878

35 files changed

+144
-48
lines changed

doc/src/sgml/ddl.sgml

+17-6
Original file line numberDiff line numberDiff line change
@@ -2611,7 +2611,7 @@ VALUES ('Albany', NULL, NULL, 'NY');
26112611
if they are inherited
26122612
from any parent tables. If you wish to remove a table and all of its
26132613
descendants, one easy way is to drop the parent table with the
2614-
<literal>CASCADE</literal> option.
2614+
<literal>CASCADE</literal> option (see <xref linkend="ddl-depend">).
26152615
</para>
26162616

26172617
<para>
@@ -3586,20 +3586,22 @@ HINT: Use DROP ... CASCADE to drop the dependent objects too.
35863586
<screen>
35873587
DROP TABLE products CASCADE;
35883588
</screen>
3589-
and all the dependent objects will be removed. In this case, it
3590-
doesn't remove the orders table, it only removes the foreign key
3591-
constraint. (If you want to check what <command>DROP ... CASCADE</> will do,
3589+
and all the dependent objects will be removed, as will any objects
3590+
that depend on them, recursively. In this case, it doesn't remove
3591+
the orders table, it only removes the foreign key constraint.
3592+
It stops there because nothing depends on the foreign key constraint.
3593+
(If you want to check what <command>DROP ... CASCADE</> will do,
35923594
run <command>DROP</> without <literal>CASCADE</> and read the
35933595
<literal>DETAIL</> output.)
35943596
</para>
35953597

35963598
<para>
3597-
All <command>DROP</> commands in <productname>PostgreSQL</> support
3599+
Almost all <command>DROP</> commands in <productname>PostgreSQL</> support
35983600
specifying <literal>CASCADE</literal>. Of course, the nature of
35993601
the possible dependencies varies with the type of the object. You
36003602
can also write <literal>RESTRICT</literal> instead of
36013603
<literal>CASCADE</literal> to get the default behavior, which is to
3602-
prevent the dropping of objects that other objects depend on.
3604+
prevent dropping objects that any other objects depend on.
36033605
</para>
36043606

36053607
<note>
@@ -3613,6 +3615,15 @@ DROP TABLE products CASCADE;
36133615
</para>
36143616
</note>
36153617

3618+
<para>
3619+
If a <command>DROP</> command lists multiple
3620+
objects, <literal>CASCADE</literal> is only required when there are
3621+
dependencies outside the specified group. For example, when saying
3622+
<literal>DROP TABLE tab1, tab2</literal> the existence of a foreign
3623+
key referencing <literal>tab1</> from <literal>tab2</> would not mean
3624+
that <literal>CASCADE</literal> is needed to succeed.
3625+
</para>
3626+
36163627
<para>
36173628
For user-defined functions, <productname>PostgreSQL</productname> tracks
36183629
dependencies associated with a function's externally-visible properties,

doc/src/sgml/ref/alter_domain.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ ALTER DOMAIN <replaceable class="PARAMETER">name</replaceable>
212212
<term><literal>CASCADE</literal></term>
213213
<listitem>
214214
<para>
215-
Automatically drop objects that depend on the constraint.
215+
Automatically drop objects that depend on the constraint,
216+
and in turn all objects that depend on those objects
217+
(see <xref linkend="ddl-depend">).
216218
</para>
217219
</listitem>
218220
</varlistentry>

doc/src/sgml/ref/alter_foreign_table.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ ALTER FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
431431
<listitem>
432432
<para>
433433
Automatically drop objects that depend on the dropped column
434-
or constraint (for example, views referencing the column).
434+
or constraint (for example, views referencing the column),
435+
and in turn all objects that depend on those objects
436+
(see <xref linkend="ddl-depend">).
435437
</para>
436438
</listitem>
437439
</varlistentry>

doc/src/sgml/ref/alter_table.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,9 @@ ALTER TABLE ALL IN TABLESPACE <replaceable class="PARAMETER">name</replaceable>
823823
<listitem>
824824
<para>
825825
Automatically drop objects that depend on the dropped column
826-
or constraint (for example, views referencing the column).
826+
or constraint (for example, views referencing the column),
827+
and in turn all objects that depend on those objects
828+
(see <xref linkend="ddl-depend">).
827829
</para>
828830
</listitem>
829831
</varlistentry>

doc/src/sgml/ref/drop_access_method.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ DROP ACCESS METHOD [ IF EXISTS ] <replaceable class="parameter">name</replaceabl
6262
<listitem>
6363
<para>
6464
Automatically drop objects that depend on the access method
65-
(such as operator classes, operator families, indexes).
65+
(such as operator classes, operator families, and indexes),
66+
and in turn all objects that depend on those objects
67+
(see <xref linkend="ddl-depend">).
6668
</para>
6769
</listitem>
6870
</varlistentry>

doc/src/sgml/ref/drop_aggregate.sgml

+4-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ DROP AGGREGATE [ IF EXISTS ] <replaceable>name</replaceable> ( <replaceable>aggr
107107
<term><literal>CASCADE</literal></term>
108108
<listitem>
109109
<para>
110-
Automatically drop objects that depend on the aggregate function.
110+
Automatically drop objects that depend on the aggregate function
111+
(such as views using it),
112+
and in turn all objects that depend on those objects
113+
(see <xref linkend="ddl-depend">).
111114
</para>
112115
</listitem>
113116
</varlistentry>

doc/src/sgml/ref/drop_collation.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ DROP COLLATION [ IF EXISTS ] <replaceable>name</replaceable> [ CASCADE | RESTRIC
6060
<term><literal>CASCADE</literal></term>
6161
<listitem>
6262
<para>
63-
Automatically drop objects that depend on the collation.
63+
Automatically drop objects that depend on the collation,
64+
and in turn all objects that depend on those objects
65+
(see <xref linkend="ddl-depend">).
6466
</para>
6567
</listitem>
6668
</varlistentry>

doc/src/sgml/ref/drop_domain.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ DROP DOMAIN [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> [, .
6262
<listitem>
6363
<para>
6464
Automatically drop objects that depend on the domain (such as
65-
table columns).
65+
table columns),
66+
and in turn all objects that depend on those objects
67+
(see <xref linkend="ddl-depend">).
6668
</para>
6769
</listitem>
6870
</varlistentry>

doc/src/sgml/ref/drop_event_trigger.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ DROP EVENT TRIGGER [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceabl
6363
<term><literal>CASCADE</literal></term>
6464
<listitem>
6565
<para>
66-
Automatically drop objects that depend on the trigger.
66+
Automatically drop objects that depend on the trigger,
67+
and in turn all objects that depend on those objects
68+
(see <xref linkend="ddl-depend">).
6769
</para>
6870
</listitem>
6971
</varlistentry>

doc/src/sgml/ref/drop_extension.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ DROP EXTENSION [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> [
6666
<term><literal>CASCADE</literal></term>
6767
<listitem>
6868
<para>
69-
Automatically drop objects that depend on the extension.
69+
Automatically drop objects that depend on the extension,
70+
and in turn all objects that depend on those objects
71+
(see <xref linkend="ddl-depend">).
7072
</para>
7173
</listitem>
7274
</varlistentry>

doc/src/sgml/ref/drop_foreign_data_wrapper.sgml

+4-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ DROP FOREIGN DATA WRAPPER [ IF EXISTS ] <replaceable class="parameter">name</rep
6363
<listitem>
6464
<para>
6565
Automatically drop objects that depend on the foreign-data
66-
wrapper (such as servers).
66+
wrapper (such as foreign tables and servers),
67+
and in turn all objects that depend on those objects
68+
(see <xref linkend="ddl-depend">).
6769
</para>
6870
</listitem>
6971
</varlistentry>
@@ -72,7 +74,7 @@ DROP FOREIGN DATA WRAPPER [ IF EXISTS ] <replaceable class="parameter">name</rep
7274
<term><literal>RESTRICT</literal></term>
7375
<listitem>
7476
<para>
75-
Refuse to drop the foreign-data wrappers if any objects depend
77+
Refuse to drop the foreign-data wrapper if any objects depend
7678
on it. This is the default.
7779
</para>
7880
</listitem>

doc/src/sgml/ref/drop_foreign_table.sgml

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ DROP FOREIGN TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceabl
5959
<listitem>
6060
<para>
6161
Automatically drop objects that depend on the foreign table (such as
62-
views).
62+
views), and in turn all objects that depend on those objects
63+
(see <xref linkend="ddl-depend">).
6364
</para>
6465
</listitem>
6566
</varlistentry>

doc/src/sgml/ref/drop_function.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ DROP FUNCTION [ IF EXISTS ] <replaceable class="parameter">name</replaceable> (
107107
<listitem>
108108
<para>
109109
Automatically drop objects that depend on the function (such as
110-
operators or triggers).
110+
operators or triggers),
111+
and in turn all objects that depend on those objects
112+
(see <xref linkend="ddl-depend">).
111113
</para>
112114
</listitem>
113115
</varlistentry>

doc/src/sgml/ref/drop_index.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ DROP INDEX [ CONCURRENTLY ] [ IF EXISTS ] <replaceable class="PARAMETER">name</r
8484
<term><literal>CASCADE</literal></term>
8585
<listitem>
8686
<para>
87-
Automatically drop objects that depend on the index.
87+
Automatically drop objects that depend on the index,
88+
and in turn all objects that depend on those objects
89+
(see <xref linkend="ddl-depend">).
8890
</para>
8991
</listitem>
9092
</varlistentry>

doc/src/sgml/ref/drop_language.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ DROP [ PROCEDURAL ] LANGUAGE [ IF EXISTS ] <replaceable class="PARAMETER">name</
7474
<listitem>
7575
<para>
7676
Automatically drop objects that depend on the language (such as
77-
functions in the language).
77+
functions in the language),
78+
and in turn all objects that depend on those objects
79+
(see <xref linkend="ddl-depend">).
7880
</para>
7981
</listitem>
8082
</varlistentry>

doc/src/sgml/ref/drop_materialized_view.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ DROP MATERIALIZED VIEW [ IF EXISTS ] <replaceable class="PARAMETER">name</replac
6464
<listitem>
6565
<para>
6666
Automatically drop objects that depend on the materialized view (such as
67-
other materialized views, or regular views).
67+
other materialized views, or regular views),
68+
and in turn all objects that depend on those objects
69+
(see <xref linkend="ddl-depend">).
6870
</para>
6971
</listitem>
7072
</varlistentry>

doc/src/sgml/ref/drop_opclass.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ DROP OPERATOR CLASS [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceab
7878
<term><literal>CASCADE</literal></term>
7979
<listitem>
8080
<para>
81-
Automatically drop objects that depend on the operator class.
81+
Automatically drop objects that depend on the operator class (such as
82+
indexes), and in turn all objects that depend on those objects
83+
(see <xref linkend="ddl-depend">).
8284
</para>
8385
</listitem>
8486
</varlistentry>

doc/src/sgml/ref/drop_operator.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ DROP OPERATOR [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> (
8383
<term><literal>CASCADE</literal></term>
8484
<listitem>
8585
<para>
86-
Automatically drop objects that depend on the operator.
86+
Automatically drop objects that depend on the operator (such as views
87+
using it), and in turn all objects that depend on those objects
88+
(see <xref linkend="ddl-depend">).
8789
</para>
8890
</listitem>
8991
</varlistentry>

doc/src/sgml/ref/drop_opfamily.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ DROP OPERATOR FAMILY [ IF EXISTS ] <replaceable class="PARAMETER">name</replacea
7979
<term><literal>CASCADE</literal></term>
8080
<listitem>
8181
<para>
82-
Automatically drop objects that depend on the operator family.
82+
Automatically drop objects that depend on the operator family,
83+
and in turn all objects that depend on those objects
84+
(see <xref linkend="ddl-depend">).
8385
</para>
8486
</listitem>
8587
</varlistentry>

doc/src/sgml/ref/drop_owned.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ DROP OWNED BY { <replaceable class="PARAMETER">name</replaceable> | CURRENT_USER
5555
<term><literal>CASCADE</literal></term>
5656
<listitem>
5757
<para>
58-
Automatically drop objects that depend on the affected objects.
58+
Automatically drop objects that depend on the affected objects,
59+
and in turn all objects that depend on those objects
60+
(see <xref linkend="ddl-depend">).
5961
</para>
6062
</listitem>
6163
</varlistentry>

doc/src/sgml/ref/drop_policy.sgml

+13-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PostgreSQL documentation
2121

2222
<refsynopsisdiv>
2323
<synopsis>
24-
DROP POLICY [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ON <replaceable class="parameter">table_name</replaceable>
24+
DROP POLICY [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ON <replaceable class="parameter">table_name</replaceable> [ CASCADE | RESTRICT ]
2525
</synopsis>
2626
</refsynopsisdiv>
2727

@@ -72,6 +72,18 @@ DROP POLICY [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ON <
7272
</listitem>
7373
</varlistentry>
7474

75+
<varlistentry>
76+
<term><literal>CASCADE</literal></term>
77+
<term><literal>RESTRICT</literal></term>
78+
79+
<listitem>
80+
<para>
81+
These key words do not have any effect, since there are no
82+
dependencies on policies.
83+
</para>
84+
</listitem>
85+
</varlistentry>
86+
7587
</variablelist>
7688
</refsect1>
7789

doc/src/sgml/ref/drop_rule.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ DROP RULE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> ON <re
7171
<term><literal>CASCADE</literal></term>
7272
<listitem>
7373
<para>
74-
Automatically drop objects that depend on the rule.
74+
Automatically drop objects that depend on the rule,
75+
and in turn all objects that depend on those objects
76+
(see <xref linkend="ddl-depend">).
7577
</para>
7678
</listitem>
7779
</varlistentry>

doc/src/sgml/ref/drop_schema.sgml

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ DROP SCHEMA [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> [, .
6767
<listitem>
6868
<para>
6969
Automatically drop objects (tables, functions, etc.) that are
70-
contained in the schema.
70+
contained in the schema,
71+
and in turn all objects that depend on those objects
72+
(see <xref linkend="ddl-depend">).
7173
</para>
7274
</listitem>
7375
</varlistentry>
@@ -84,6 +86,15 @@ DROP SCHEMA [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> [, .
8486
</variablelist>
8587
</refsect1>
8688

89+
<refsect1>
90+
<title>Notes</title>
91+
92+
<para>
93+
Using the <literal>CASCADE</literal> option might make the command
94+
remove objects in other schemas besides the one(s) named.
95+
</para>
96+
</refsect1>
97+
8798
<refsect1>
8899
<title>Examples</title>
89100

doc/src/sgml/ref/drop_sequence.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ DROP SEQUENCE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> [,
6161
<term><literal>CASCADE</literal></term>
6262
<listitem>
6363
<para>
64-
Automatically drop objects that depend on the sequence.
64+
Automatically drop objects that depend on the sequence,
65+
and in turn all objects that depend on those objects
66+
(see <xref linkend="ddl-depend">).
6567
</para>
6668
</listitem>
6769
</varlistentry>

doc/src/sgml/ref/drop_server.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ DROP SERVER [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [ CA
6363
<listitem>
6464
<para>
6565
Automatically drop objects that depend on the server (such as
66-
user mappings).
66+
user mappings),
67+
and in turn all objects that depend on those objects
68+
(see <xref linkend="ddl-depend">).
6769
</para>
6870
</listitem>
6971
</varlistentry>

doc/src/sgml/ref/drop_table.sgml

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ DROP TABLE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable> [, ..
7575
<listitem>
7676
<para>
7777
Automatically drop objects that depend on the table (such as
78-
views).
78+
views),
79+
and in turn all objects that depend on those objects
80+
(see <xref linkend="ddl-depend">).
7981
</para>
8082
</listitem>
8183
</varlistentry>

doc/src/sgml/ref/drop_transform.sgml

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<refsynopsisdiv>
2020
<synopsis>
21-
DROP TRANSFORM [ IF EXISTS ] FOR <replaceable>type_name</replaceable> LANGUAGE <replaceable>lang_name</replaceable>
21+
DROP TRANSFORM [ IF EXISTS ] FOR <replaceable>type_name</replaceable> LANGUAGE <replaceable>lang_name</replaceable> [ CASCADE | RESTRICT ]
2222
</synopsis>
2323
</refsynopsisdiv>
2424

@@ -74,7 +74,9 @@ DROP TRANSFORM [ IF EXISTS ] FOR <replaceable>type_name</replaceable> LANGUAGE <
7474
<term><literal>CASCADE</literal></term>
7575
<listitem>
7676
<para>
77-
Automatically drop objects that depend on the transform.
77+
Automatically drop objects that depend on the transform,
78+
and in turn all objects that depend on those objects
79+
(see <xref linkend="ddl-depend">).
7880
</para>
7981
</listitem>
8082
</varlistentry>

0 commit comments

Comments
 (0)