if they are inherited
from any parent tables. If you wish to remove a table and all of its
descendants, one easy way is to drop the parent table with the
- <literal>CASCADE</literal> option.
+ <literal>CASCADE</literal> option (see <xref linkend="ddl-depend">).
</para>
<para>
<screen>
DROP TABLE products CASCADE;
</screen>
- and all the dependent objects will be removed. In this case, it
- doesn't remove the orders table, it only removes the foreign key
- constraint. (If you want to check what <command>DROP ... CASCADE</> will do,
+ and all the dependent objects will be removed, as will any objects
+ that depend on them, recursively. In this case, it doesn't remove
+ the orders table, it only removes the foreign key constraint.
+ It stops there because nothing depends on the foreign key constraint.
+ (If you want to check what <command>DROP ... CASCADE</> will do,
run <command>DROP</> without <literal>CASCADE</> and read the
<literal>DETAIL</> output.)
</para>
<para>
- All <command>DROP</> commands in <productname>PostgreSQL</> support
+ Almost all <command>DROP</> commands in <productname>PostgreSQL</> support
specifying <literal>CASCADE</literal>. Of course, the nature of
the possible dependencies varies with the type of the object. You
can also write <literal>RESTRICT</literal> instead of
<literal>CASCADE</literal> to get the default behavior, which is to
- prevent the dropping of objects that other objects depend on.
+ prevent dropping objects that any other objects depend on.
</para>
<note>
</para>
</note>
+ <para>
+ If a <command>DROP</> command lists multiple
+ objects, <literal>CASCADE</literal> is only required when there are
+ dependencies outside the specified group. For example, when saying
+ <literal>DROP TABLE tab1, tab2</literal> the existence of a foreign
+ key referencing <literal>tab1</> from <literal>tab2</> would not mean
+ that <literal>CASCADE</literal> is needed to succeed.
+ </para>
+
<para>
For user-defined functions, <productname>PostgreSQL</productname> tracks
dependencies associated with a function's externally-visible properties,
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the constraint.
+ Automatically drop objects that depend on the constraint,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the dropped column
- or constraint (for example, views referencing the column).
+ or constraint (for example, views referencing the column),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the dropped column
- or constraint (for example, views referencing the column).
+ or constraint (for example, views referencing the column),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the access method
- (such as operator classes, operator families, indexes).
+ (such as operator classes, operator families, and indexes),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the aggregate function.
+ Automatically drop objects that depend on the aggregate function
+ (such as views using it),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the collation.
+ Automatically drop objects that depend on the collation,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the domain (such as
- table columns).
+ table columns),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the trigger.
+ Automatically drop objects that depend on the trigger,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the extension.
+ Automatically drop objects that depend on the extension,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the foreign-data
- wrapper (such as servers).
+ wrapper (such as foreign tables and servers),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>RESTRICT</literal></term>
<listitem>
<para>
- Refuse to drop the foreign-data wrappers if any objects depend
+ Refuse to drop the foreign-data wrapper if any objects depend
on it. This is the default.
</para>
</listitem>
<listitem>
<para>
Automatically drop objects that depend on the foreign table (such as
- views).
+ views), and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the function (such as
- operators or triggers).
+ operators or triggers),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the index.
+ Automatically drop objects that depend on the index,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the language (such as
- functions in the language).
+ functions in the language),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the materialized view (such as
- other materialized views, or regular views).
+ other materialized views, or regular views),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the operator class.
+ Automatically drop objects that depend on the operator class (such as
+ indexes), and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the operator.
+ Automatically drop objects that depend on the operator (such as views
+ using it), and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the operator family.
+ Automatically drop objects that depend on the operator family,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the affected objects.
+ Automatically drop objects that depend on the affected objects,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<refsynopsisdiv>
<synopsis>
-DROP POLICY [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ON <replaceable class="parameter">table_name</replaceable>
+DROP POLICY [ IF EXISTS ] <replaceable class="parameter">name</replaceable> ON <replaceable class="parameter">table_name</replaceable> [ CASCADE | RESTRICT ]
</synopsis>
</refsynopsisdiv>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><literal>CASCADE</literal></term>
+ <term><literal>RESTRICT</literal></term>
+
+ <listitem>
+ <para>
+ These key words do not have any effect, since there are no
+ dependencies on policies.
+ </para>
+ </listitem>
+ </varlistentry>
+
</variablelist>
</refsect1>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the rule.
+ Automatically drop objects that depend on the rule,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects (tables, functions, etc.) that are
- contained in the schema.
+ contained in the schema,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
+ <refsect1>
+ <title>Notes</title>
+
+ <para>
+ Using the <literal>CASCADE</literal> option might make the command
+ remove objects in other schemas besides the one(s) named.
+ </para>
+ </refsect1>
+
<refsect1>
<title>Examples</title>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the sequence.
+ Automatically drop objects that depend on the sequence,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the server (such as
- user mappings).
+ user mappings),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the table (such as
- views).
+ views),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<refsynopsisdiv>
<synopsis>
-DROP TRANSFORM [ IF EXISTS ] FOR <replaceable>type_name</replaceable> LANGUAGE <replaceable>lang_name</replaceable>
+DROP TRANSFORM [ IF EXISTS ] FOR <replaceable>type_name</replaceable> LANGUAGE <replaceable>lang_name</replaceable> [ CASCADE | RESTRICT ]
</synopsis>
</refsynopsisdiv>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the transform.
+ Automatically drop objects that depend on the transform,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the trigger.
+ Automatically drop objects that depend on the trigger,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the text search configuration.
+ Automatically drop objects that depend on the text search configuration,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the text search dictionary.
+ Automatically drop objects that depend on the text search dictionary,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the text search parser.
+ Automatically drop objects that depend on the text search parser,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<term><literal>CASCADE</literal></term>
<listitem>
<para>
- Automatically drop objects that depend on the text search template.
+ Automatically drop objects that depend on the text search template,
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the type (such as
- table columns, functions, operators).
+ table columns, functions, and operators),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
<listitem>
<para>
Automatically drop objects that depend on the view (such as
- other views).
+ other views),
+ and in turn all objects that depend on those objects
+ (see <xref linkend="ddl-depend">).
</para>
</listitem>
</varlistentry>
*
* Drop a postgresql DBMS role
*
- * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
- * might own objects in multiple databases, there is presently no way to
- * implement either cascading or restricting. Caveat DBA.
+ * XXX Ideally this would have CASCADE/RESTRICT options, but a role
+ * might own objects in multiple databases, and there is presently no way to
+ * implement cascading to other databases. So we always behave as RESTRICT.
*****************************************************************************/
DropRoleStmt:
*
* Drop a postgresql DBMS user
*
- * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
- * might own objects in multiple databases, there is presently no way to
- * implement either cascading or restricting. Caveat DBA.
+ * XXX As with DROP ROLE, no CASCADE/RESTRICT here.
*****************************************************************************/
DropUserStmt:
*
* Drop a postgresql group
*
- * XXX see above notes about cascading DROP USER; groups have same problem.
+ * XXX As with DROP ROLE, no CASCADE/RESTRICT here.
*****************************************************************************/
DropGroupStmt:
* QUERY :
* DROP USER MAPPING FOR auth_ident SERVER name
*
+ * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
+ * only pro forma; but the SQL standard doesn't show one.
****************************************************************************/
DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name