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
- CASCADE option.
+ CASCADE option (see ).
DROP TABLE products CASCADE;
- 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 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 DROP ... CASCADE> will do,
run DROP> without CASCADE> and read the
DETAIL> output.)
- All
DROP> commands in PostgreSQL> support
+ Al
most all
DROP> commands in PostgreSQL> support
specifying CASCADE. Of course, the nature of
the possible dependencies varies with the type of the object. You
can also write RESTRICT instead of
CASCADE 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.
+ If a DROP> command lists multiple
+ objects, CASCADE is only required when there are
+ dependencies outside the specified group. For example, when saying
+ DROP TABLE tab1, tab2 the existence of a foreign
+ key referencing tab1> from tab2> would not mean
+ that CASCADE is needed to succeed.
+
+
For user-defined functions,
PostgreSQL tracks
dependencies associated with a function's externally-visible properties,
CASCADE
- 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 ).
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 ).
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 ).
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 ).
CASCADE
- 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 ).
CASCADE
- 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 ).
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 ).
CASCADE
- 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 ).
CASCADE
- 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 ).
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 ).
RESTRICT
- 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.
Automatically drop objects that depend on the foreign table (such as
- views).
+ views), and in turn all objects that depend on those objects
+ (see ).
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 ).
CASCADE
- 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 ).
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 ).
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 ).
CASCADE
- 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 ).
CASCADE
- 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 ).
CASCADE
- 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 ).
CASCADE
- 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 ).
-DROP POLICY [ IF EXISTS ] name ON table_name
+DROP POLICY [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ]
+
+ CASCADE
+ RESTRICT
+
+
+ These key words do not have any effect, since there are no
+ dependencies on policies.
+
+
+
+
CASCADE
- 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 ).
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 ).
+
+
Notes
+
+ Using the CASCADE option might make the command
+ remove objects in other schemas besides the one(s) named.
+
+
+
Examples
CASCADE
- 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 ).
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 ).
Automatically drop objects that depend on the table (such as
- views).
+ views),
+ and in turn all objects that depend on those objects
+ (see ).
-DROP TRANSFORM [ IF EXISTS ] FOR type_name LANGUAGE lang_name
+DROP TRANSFORM [ IF EXISTS ] FOR type_name LANGUAGE lang_name [ CASCADE | RESTRICT ]
CASCADE
- 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 ).
CASCADE
- 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 ).
CASCADE
- 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 ).
CASCADE
- 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 ).
CASCADE
- 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 ).
CASCADE
- 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 ).
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 ).
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 ).
*
* 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