Doc: clarify that DROP ... CASCADE is recursive.
authorTom Lane
Fri, 12 Aug 2016 22:45:18 +0000 (18:45 -0400)
committerTom Lane
Fri, 12 Aug 2016 22:45:18 +0000 (18:45 -0400)
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[email protected]>

35 files changed:
doc/src/sgml/ddl.sgml
doc/src/sgml/ref/alter_domain.sgml
doc/src/sgml/ref/alter_foreign_table.sgml
doc/src/sgml/ref/alter_table.sgml
doc/src/sgml/ref/drop_access_method.sgml
doc/src/sgml/ref/drop_aggregate.sgml
doc/src/sgml/ref/drop_collation.sgml
doc/src/sgml/ref/drop_domain.sgml
doc/src/sgml/ref/drop_event_trigger.sgml
doc/src/sgml/ref/drop_extension.sgml
doc/src/sgml/ref/drop_foreign_data_wrapper.sgml
doc/src/sgml/ref/drop_foreign_table.sgml
doc/src/sgml/ref/drop_function.sgml
doc/src/sgml/ref/drop_index.sgml
doc/src/sgml/ref/drop_language.sgml
doc/src/sgml/ref/drop_materialized_view.sgml
doc/src/sgml/ref/drop_opclass.sgml
doc/src/sgml/ref/drop_operator.sgml
doc/src/sgml/ref/drop_opfamily.sgml
doc/src/sgml/ref/drop_owned.sgml
doc/src/sgml/ref/drop_policy.sgml
doc/src/sgml/ref/drop_rule.sgml
doc/src/sgml/ref/drop_schema.sgml
doc/src/sgml/ref/drop_sequence.sgml
doc/src/sgml/ref/drop_server.sgml
doc/src/sgml/ref/drop_table.sgml
doc/src/sgml/ref/drop_transform.sgml
doc/src/sgml/ref/drop_trigger.sgml
doc/src/sgml/ref/drop_tsconfig.sgml
doc/src/sgml/ref/drop_tsdictionary.sgml
doc/src/sgml/ref/drop_tsparser.sgml
doc/src/sgml/ref/drop_tstemplate.sgml
doc/src/sgml/ref/drop_type.sgml
doc/src/sgml/ref/drop_view.sgml
src/backend/parser/gram.y

index 954c3a9b9e4dd715c52ac50216c1dc8b006baab1..a393813b3809df196fed11dcb266bb4950e14823 100644 (file)
@@ -2611,7 +2611,7 @@ VALUES ('Albany', NULL, NULL, 'NY');
    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 ).
   
 
   
@@ -3586,20 +3586,22 @@ HINT:  Use DROP ... CASCADE to drop the dependent objects too.
 
 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
+   Almost alDROP 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.
   
 
   
@@ -3613,6 +3615,15 @@ DROP TABLE products CASCADE;
    
   
 
+  
+   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,
index ac9a5b3f87dfcc0b743ca869c39c82aee5bc2aa5..74dda73c699210d33d6adc4b78255f6a7c8df270 100644 (file)
@@ -212,7 +212,9 @@ ALTER DOMAIN name
       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 ).
        
       
      
index 4329d43a1ed2b2b67b9b9d6cc27cf70dd43a71c0..b1692842b2696ac10e7002278daee3aa756309b8 100644 (file)
@@ -431,7 +431,9 @@ ALTER FOREIGN TABLE [ IF EXISTS ] name
       
        
         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 ).
        
       
      
index 5ca211e5f87301f9c2cef88e0503e480c165e3e9..6f51cbc8962cc674bbaccbf51315cfcc0ed14701 100644 (file)
@@ -823,7 +823,9 @@ ALTER TABLE ALL IN TABLESPACE name
       
        
         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 ).
        
       
      
index b899c71e1a3840bedc1aafd4e3fcd49e84e1cff4..8aa9197fe4a3bcee66d75e047cac43821a81f0c7 100644 (file)
@@ -62,7 +62,9 @@ DROP ACCESS METHOD [ IF EXISTS ] name
     
      
       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 ).
      
     
    
index 37683e51eff3671e2528ed79bf9e7a576ff76c4a..c27c5eadf9278f047608b5284f801776f8a5bcb9 100644 (file)
@@ -107,7 +107,10 @@ DROP AGGREGATE [ IF EXISTS ] name ( aggr
     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 ).
      
     
    
index f00c88679b7a1b0e5121de604b14c243d5d69c7e..2177d8e5d65371aea532e5747d0460b53a90be6d 100644 (file)
@@ -60,7 +60,9 @@ DROP COLLATION [ IF EXISTS ] name [ CASCADE | RESTRIC
      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 ).
       
      
     
index 995d09ec8e9119dfb25793b4cec15dd4d000ea8b..e14795e6a30f289ed12f6d64694eb6f66b2e9a54 100644 (file)
@@ -62,7 +62,9 @@ DROP DOMAIN [ IF EXISTS ] name [, .
     
      
       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 ).
      
     
    
index cf42e150614d4478ce2c5cb1879063c795df4f5a..6e3ee22d7bbc4cc3fb2cf1b3c85a01b1ce676df4 100644 (file)
@@ -63,7 +63,9 @@ DROP EVENT TRIGGER [ IF EXISTS ] name
     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 ).
      
     
    
index 3bb9d9cb4cf848fef899ecd61bfbf6c2e5c0eab0..7438a08bb36130f54253e2c896e1b5dfec41de40 100644 (file)
@@ -66,7 +66,9 @@ DROP EXTENSION [ IF EXISTS ] name [
     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 ).
      
     
    
index e43e0bda8b0621e371ebf67b69b59458c4a5234c..824d72c1766d8a14ea1d662a1d3bcaa5ac198146 100644 (file)
@@ -63,7 +63,9 @@ DROP FOREIGN DATA WRAPPER [ IF EXISTS ] name
     
      
       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 ).
      
     
    
@@ -72,7 +74,7 @@ DROP FOREIGN DATA WRAPPER [ IF EXISTS ] name
     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.
      
     
index 3c6376413e79492b31d0bd2058c5124e18f0322c..f9d1e459d266b10d8c6f9118d08ff6d769b7daf4 100644 (file)
@@ -59,7 +59,8 @@ DROP FOREIGN TABLE [ IF EXISTS ] name
     
      
       Automatically drop objects that depend on the foreign table (such as
-      views).
+      views), and in turn all objects that depend on those objects
+      (see ).
      
     
    
index 51b8ede5fbfb04528285c3cba23b7db673cb15df..5883d138115c855256400144bac54e6d4fd9a52a 100644 (file)
@@ -107,7 +107,9 @@ DROP FUNCTION [ IF EXISTS ] name (
     
      
       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 ).
      
     
    
index d66d30edf7442c6a63b4cb68263415e6a5a5d9f6..6fe108ded25f6e264aaf52fffc1fad9b271d1872 100644 (file)
@@ -84,7 +84,9 @@ DROP INDEX [ CONCURRENTLY ] [ IF EXISTS ] name
     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 ).
      
     
    
index defae43c1a205b0a6d515f3977296a79fc50ecd0..0facc62876669f37bb42bd6bd7254ac2820865bf 100644 (file)
@@ -74,7 +74,9 @@ DROP [ PROCEDURAL ] LANGUAGE [ IF EXISTS ] name
     
      
       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 ).
      
     
    
index f3ddfb06e8ce425e552ec92b379c61efcabc68b9..36ec33ceb08aef7129851c993747e46c99940498 100644 (file)
@@ -64,7 +64,9 @@ DROP MATERIALIZED VIEW [ IF EXISTS ] name
     
      
       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 ).
      
     
    
index 2ee8f883b6c3b078d676f5525d47aa389cf85f10..187a9a4d1f722093d6d8b5cc7930e915565dd374 100644 (file)
@@ -78,7 +78,9 @@ DROP OPERATOR CLASS [ IF EXISTS ] name
     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 ).
      
     
    
index 902e4f3fa6aa2b2d48d65c5dd551db92dbebe171..13dd974f384f2ea4c118d02aaf7ee3b4615dff53 100644 (file)
@@ -83,7 +83,9 @@ DROP OPERATOR [ IF EXISTS ] name (
     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 ).
      
     
    
index d665e938833b8978e2caaecabea4625e2834019b..53bce2288377787bc28e4bdd570e30b1c48bca11 100644 (file)
@@ -79,7 +79,9 @@ DROP OPERATOR FAMILY [ IF EXISTS ] name
     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 ).
      
     
    
index d03cc57845082bf2ddb02e7e7f00663efce38b12..81694b88e535b5d8a2210d20dbf15c3b29d0cdba 100644 (file)
@@ -55,7 +55,9 @@ DROP OWNED BY { name | CURRENT_USER
     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 ).
      
     
    
index e5eaaa785bbdfae5b725aa7cc1c9df3f1cf7dfd0..69c87c0ade75ede0f577a8a9f15aa87a7a067c0b 100644 (file)
@@ -21,7 +21,7 @@ PostgreSQL documentation
 
  
 
-DROP POLICY [ IF EXISTS ] name ON table_name
+DROP POLICY [ IF EXISTS ] name ON table_name [ CASCADE | RESTRICT ]
 
  
 
@@ -72,6 +72,18 @@ DROP POLICY [ IF EXISTS ] name ON <
     
    
 
+   
+    CASCADE
+    RESTRICT
+
+    
+     
+      These key words do not have any effect, since there are no
+      dependencies on policies.
+     
+    
+   
+
   
  
 
index 16ab2b1bb571b4739e0308e0e8433e8dfe0f6e32..d4905a69c9dd79df38bf19d420d2ed71e7eb090a 100644 (file)
@@ -71,7 +71,9 @@ DROP RULE [ IF EXISTS ] name ON 
     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 ).
      
     
    
index e3071227fe558eeedec1d9fda1cee53440782d89..5b1697fff206c81b289b55662a9f7283ad90637b 100644 (file)
@@ -67,7 +67,9 @@ DROP SCHEMA [ IF EXISTS ] name [, .
     
      
       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 ).
      
     
    
@@ -84,6 +86,15 @@ DROP SCHEMA [ IF EXISTS ] name [, .
   
  
 
+  Notes
+
+  
+   Using the CASCADE option might make the command
+   remove objects in other schemas besides the one(s) named.
+  
+
  
   Examples
 
index b0f9cddda744e7a321a0a6b236d301a05141d597..f0e1edc81c58d96503f9ebef046b2a43b37be8bb 100644 (file)
@@ -61,7 +61,9 @@ DROP SEQUENCE [ IF EXISTS ] name [,
     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 ).
      
     
    
index 497d83fb4aa61b076f8e7d948921cd50c0364882..f08dd7767dfc0d888866003406e6b733c41369f9 100644 (file)
@@ -63,7 +63,9 @@ DROP SERVER [ IF EXISTS ] name [ CA
     
      
       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 ).
      
     
    
index 4cb1f49b3aa61415f9d7dc1378a4484979d471a5..94d28b06fbc7a67a54237b8d6955fe2b7c8a54ef 100644 (file)
@@ -75,7 +75,9 @@ DROP TABLE [ IF EXISTS ] name [, ..
     
      
       Automatically drop objects that depend on the table (such as
-      views).
+      views),
+      and in turn all objects that depend on those objects
+      (see ).
      
     
    
index 59ff87cfe48c20e4c0e97ea373cf0279ffc68ff1..698920a22663de82b2eab9c87ddb55aa54ed1751 100644 (file)
@@ -18,7 +18,7 @@
 
  
 
-DROP TRANSFORM [ IF EXISTS ] FOR type_name LANGUAGE lang_name
+DROP TRANSFORM [ IF EXISTS ] FOR type_name LANGUAGE lang_name [ CASCADE | RESTRICT ]
 
  
 
@@ -74,7 +74,9 @@ DROP TRANSFORM [ IF EXISTS ] FOR type_name LANGUAGE <
      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 ).
       
      
     
index 2067aefca247e663105b3a1ca9037d048d6b4607..d400b8383f437485b54dff72d58586d29b5b3658 100644 (file)
@@ -73,7 +73,9 @@ DROP TRIGGER [ IF EXISTS ] name ON
     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 ).
      
     
    
index 831485e6a68626774d9de14da0e0702e91c87208..0096e0092d37447979dd5a5296b83963c2aaf828 100644 (file)
@@ -64,7 +64,9 @@ DROP TEXT SEARCH CONFIGURATION [ IF EXISTS ] name
     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 ).
      
     
    
index 44b30cbe6767524ff049192315d833ea2a49e122..803abf8cba9dce07181d39dc25539fd3a3589471 100644 (file)
@@ -64,7 +64,9 @@ DROP TEXT SEARCH DICTIONARY [ IF EXISTS ] name
     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 ).
      
     
    
index 789e807dbe2b1dfa1b2d52f2d704a0efaf33671f..fa997201610a241d178a829fe9f1c6816f2dfc80 100644 (file)
@@ -62,7 +62,9 @@ DROP TEXT SEARCH PARSER [ IF EXISTS ] name
     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 ).
      
     
    
index ebf81367441f3231026d9cc854ea51f14f27a521..9d051eb6197883ee6b6e3a257199ae0edfa4faf5 100644 (file)
@@ -63,7 +63,9 @@ DROP TEXT SEARCH TEMPLATE [ IF EXISTS ] name
     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 ).
      
     
    
index 98c8a3cbef5411ee2654fc65dbd3866081b4b14f..2c7b8fe9f6b3c79b935763c684b62d299953da55 100644 (file)
@@ -62,7 +62,9 @@ DROP TYPE [ IF EXISTS ] name [, ...
     
      
       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 ).
      
     
    
index 8b43be5360079cd19602360b3b4a7697e31930d5..40f23561884a20d6705f910414b3ee80902aaea5 100644 (file)
@@ -62,7 +62,9 @@ DROP VIEW [ IF EXISTS ] name [, ...
     
      
       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 ).
      
     
    
index 0cae44641f83db5158245f1bd53dd518679154cd..6a0f7b393cb9655289cc647bfbc347142d8e2fa9 100644 (file)
@@ -1126,9 +1126,9 @@ AlterUserSetStmt:
  *
  * 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:
@@ -1152,9 +1152,7 @@ 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:
@@ -1220,7 +1218,7 @@ add_drop: ADD_P                                   { $$ = +1; }
  *
  * 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:
@@ -4574,6 +4572,8 @@ auth_ident: RoleSpec          { $$ = $1; }
  *     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