Combine several DROP variants into generic DropStmt
authorPeter Eisentraut <peter_e@gmx.net>
Wed, 22 Feb 2017 04:10:07 +0000 (23:10 -0500)
committerPeter Eisentraut <peter_e@gmx.net>
Mon, 6 Mar 2017 18:31:47 +0000 (13:31 -0500)
Combine DROP of FOREIGN DATA WRAPPER, SERVER, POLICY, RULE, and TRIGGER
into generic DropStmt grammar.

Reviewed-by: Jim Nasby <Jim.Nasby@BlueTreble.com>
Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
doc/src/sgml/ref/drop_foreign_data_wrapper.sgml
doc/src/sgml/ref/drop_server.sgml
src/backend/parser/gram.y

index 824d72c1766d8a14ea1d662a1d3bcaa5ac198146..702cc021dbcc0f97afc8b50970ceee7132615a11 100644 (file)
@@ -21,7 +21,7 @@ PostgreSQL documentation
 
  <refsynopsisdiv>
 <synopsis>
-DROP FOREIGN DATA WRAPPER [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [ CASCADE | RESTRICT ]
+DROP FOREIGN DATA WRAPPER [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [, ...] [ CASCADE | RESTRICT ]
 </synopsis>
  </refsynopsisdiv>
 
index f08dd7767dfc0d888866003406e6b733c41369f9..42acdd41dc159c736d3cd14e8bf7ada3836d3494 100644 (file)
@@ -21,7 +21,7 @@ PostgreSQL documentation
 
  <refsynopsisdiv>
 <synopsis>
-DROP SERVER [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [ CASCADE | RESTRICT ]
+DROP SERVER [ IF EXISTS ] <replaceable class="parameter">name</replaceable> [, ...] [ CASCADE | RESTRICT ]
 </synopsis>
  </refsynopsisdiv>
 
index 542b09b4b0f771a523b7e3517a95e935240f830f..083124ed3bef51c35a6f7d808d631faa6a852dab 100644 (file)
@@ -263,10 +263,10 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
                CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
                CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
                DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
-               DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
-               DropPolicyStmt DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
+               DropAssertStmt DropCastStmt DropRoleStmt
+               DropUserStmt DropdbStmt DropTableSpaceStmt
                DropTransformStmt
-               DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
+               DropUserMappingStmt ExplainStmt FetchStmt
                GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
                ListenStmt LoadStmt LockStmt NotifyStmt ExplainableStmt PreparableStmt
                CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
@@ -440,7 +440,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
 %type <boolean> copy_from opt_program
 
 %type <ival>   opt_column event cursor_options opt_hold opt_set_data
-%type <objtype>        drop_type_any_name drop_type_name
+%type <objtype>        drop_type_any_name drop_type_name drop_type_name_on_any_name
                                comment_type_any_name comment_type_name
                                security_label_type_any_name security_label_type_name
 
@@ -885,20 +885,15 @@ stmt :
                        | DoStmt
                        | DropAssertStmt
                        | DropCastStmt
-                       | DropFdwStmt
-                       | DropForeignServerStmt
                        | DropGroupStmt
                        | DropOpClassStmt
                        | DropOpFamilyStmt
                        | DropOwnedStmt
-                       | DropPolicyStmt
                        | DropPLangStmt
-                       | DropRuleStmt
                        | DropStmt
                        | DropSubscriptionStmt
                        | DropTableSpaceStmt
                        | DropTransformStmt
-                       | DropTrigStmt
                        | DropRoleStmt
                        | DropUserStmt
                        | DropUserMappingStmt
@@ -4511,35 +4506,6 @@ opt_fdw_options:
                        | /*EMPTY*/                                                     { $$ = NIL; }
                ;
 
-/*****************************************************************************
- *
- *             QUERY :
- *                             DROP FOREIGN DATA WRAPPER name
- *
- ****************************************************************************/
-
-DropFdwStmt: DROP FOREIGN DATA_P WRAPPER name opt_drop_behavior
-                               {
-                                       DropStmt *n = makeNode(DropStmt);
-                                       n->removeType = OBJECT_FDW;
-                                       n->objects = list_make1(makeString($5));
-                                       n->missing_ok = false;
-                                       n->behavior = $6;
-                                       n->concurrent = false;
-                                       $$ = (Node *) n;
-                               }
-                               |  DROP FOREIGN DATA_P WRAPPER IF_P EXISTS name opt_drop_behavior
-                               {
-                                       DropStmt *n = makeNode(DropStmt);
-                                       n->removeType = OBJECT_FDW;
-                                       n->objects = list_make1(makeString($7));
-                                       n->missing_ok = true;
-                                       n->behavior = $8;
-                                       n->concurrent = false;
-                                       $$ = (Node *) n;
-                               }
-               ;
-
 /*****************************************************************************
  *
  *             QUERY :
@@ -4671,35 +4637,6 @@ opt_foreign_server_version:
                        | /*EMPTY*/                             { $$ = NULL; }
                ;
 
-/*****************************************************************************
- *
- *             QUERY :
- *                             DROP SERVER name
- *
- ****************************************************************************/
-
-DropForeignServerStmt: DROP SERVER name opt_drop_behavior
-                               {
-                                       DropStmt *n = makeNode(DropStmt);
-                                       n->removeType = OBJECT_FOREIGN_SERVER;
-                                       n->objects = list_make1(makeString($3));
-                                       n->missing_ok = false;
-                                       n->behavior = $4;
-                                       n->concurrent = false;
-                                       $$ = (Node *) n;
-                               }
-                               |  DROP SERVER IF_P EXISTS name opt_drop_behavior
-                               {
-                                       DropStmt *n = makeNode(DropStmt);
-                                       n->removeType = OBJECT_FOREIGN_SERVER;
-                                       n->objects = list_make1(makeString($5));
-                                       n->missing_ok = true;
-                                       n->behavior = $6;
-                                       n->concurrent = false;
-                                       $$ = (Node *) n;
-                               }
-               ;
-
 /*****************************************************************************
  *
  *             QUERY :
@@ -4975,7 +4912,6 @@ AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generi
  *                                     [USING (qual)] [WITH CHECK (with check qual)]
  *                             ALTER POLICY name ON table [TO role, ...]
  *                                     [USING (qual)] [WITH CHECK (with check qual)]
- *                             DROP POLICY name ON table
  *
  *****************************************************************************/
 
@@ -5010,29 +4946,6 @@ AlterPolicyStmt:
                                }
                ;
 
-DropPolicyStmt:
-                       DROP POLICY name ON any_name opt_drop_behavior
-                               {
-                                       DropStmt *n = makeNode(DropStmt);
-                                       n->removeType = OBJECT_POLICY;
-                                       n->objects = list_make1(lappend($5, makeString($3)));
-                                       n->behavior = $6;
-                                       n->missing_ok = false;
-                                       n->concurrent = false;
-                                       $$ = (Node *) n;
-                               }
-                       | DROP POLICY IF_P EXISTS name ON any_name opt_drop_behavior
-                               {
-                                       DropStmt *n = makeNode(DropStmt);
-                                       n->removeType = OBJECT_POLICY;
-                                       n->objects = list_make1(lappend($7, makeString($5)));
-                                       n->behavior = $8;
-                                       n->missing_ok = true;
-                                       n->concurrent = false;
-                                       $$ = (Node *) n;
-                               }
-               ;
-
 RowSecurityOptionalExpr:
                        USING '(' a_expr ')'    { $$ = $3; }
                        | /* EMPTY */                   { $$ = NULL; }
@@ -5105,7 +5018,6 @@ CreateAmStmt: CREATE ACCESS METHOD name TYPE_P INDEX HANDLER handler_name
  *
  *             QUERIES :
  *                             CREATE TRIGGER ...
- *                             DROP TRIGGER ...
  *
  *****************************************************************************/
 
@@ -5332,30 +5244,6 @@ ConstraintAttributeElem:
                ;
 
 
-DropTrigStmt:
-                       DROP TRIGGER name ON any_name opt_drop_behavior
-                               {
-                                       DropStmt *n = makeNode(DropStmt);
-                                       n->removeType = OBJECT_TRIGGER;
-                                       n->objects = list_make1(lappend($5, makeString($3)));
-                                       n->behavior = $6;
-                                       n->missing_ok = false;
-                                       n->concurrent = false;
-                                       $$ = (Node *) n;
-                               }
-                       | DROP TRIGGER IF_P EXISTS name ON any_name opt_drop_behavior
-                               {
-                                       DropStmt *n = makeNode(DropStmt);
-                                       n->removeType = OBJECT_TRIGGER;
-                                       n->objects = list_make1(lappend($7, makeString($5)));
-                                       n->behavior = $8;
-                                       n->missing_ok = true;
-                                       n->concurrent = false;
-                                       $$ = (Node *) n;
-                               }
-               ;
-
-
 /*****************************************************************************
  *
  *             QUERIES :
@@ -6034,6 +5922,26 @@ DropStmt:        DROP drop_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
                                        n->concurrent = false;
                                        $$ = (Node *)n;
                                }
+                       | DROP drop_type_name_on_any_name name ON any_name opt_drop_behavior
+                               {
+                                       DropStmt *n = makeNode(DropStmt);
+                                       n->removeType = $2;
+                                       n->objects = list_make1(lappend($5, makeString($3)));
+                                       n->behavior = $6;
+                                       n->missing_ok = false;
+                                       n->concurrent = false;
+                                       $$ = (Node *) n;
+                               }
+                       | DROP drop_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
+                               {
+                                       DropStmt *n = makeNode(DropStmt);
+                                       n->removeType = $2;
+                                       n->objects = list_make1(lappend($7, makeString($5)));
+                                       n->behavior = $8;
+                                       n->missing_ok = true;
+                                       n->concurrent = false;
+                                       $$ = (Node *) n;
+                               }
                        | DROP TYPE_P type_name_list opt_drop_behavior
                                {
                                        DropStmt *n = makeNode(DropStmt);
@@ -6117,8 +6025,17 @@ drop_type_name:
                        ACCESS METHOD                                                   { $$ = OBJECT_ACCESS_METHOD; }
                        | EVENT TRIGGER                                                 { $$ = OBJECT_EVENT_TRIGGER; }
                        | EXTENSION                                                             { $$ = OBJECT_EXTENSION; }
+                       | FOREIGN DATA_P WRAPPER                                { $$ = OBJECT_FDW; }
                        | PUBLICATION                                                   { $$ = OBJECT_PUBLICATION; }
                        | SCHEMA                                                                { $$ = OBJECT_SCHEMA; }
+                       | SERVER                                                                { $$ = OBJECT_FOREIGN_SERVER; }
+               ;
+
+/* object types attached to a table */
+drop_type_name_on_any_name:
+                       POLICY                                                                  { $$ = OBJECT_POLICY; }
+                       | RULE                                                                  { $$ = OBJECT_RULE; }
+                       | TRIGGER                                                               { $$ = OBJECT_TRIGGER; }
                ;
 
 any_name_list:
@@ -9277,30 +9194,6 @@ opt_instead:
                ;
 
 
-DropRuleStmt:
-                       DROP RULE name ON any_name opt_drop_behavior
-                               {
-                                       DropStmt *n = makeNode(DropStmt);
-                                       n->removeType = OBJECT_RULE;
-                                       n->objects = list_make1(lappend($5, makeString($3)));
-                                       n->behavior = $6;
-                                       n->missing_ok = false;
-                                       n->concurrent = false;
-                                       $$ = (Node *) n;
-                               }
-                       | DROP RULE IF_P EXISTS name ON any_name opt_drop_behavior
-                               {
-                                       DropStmt *n = makeNode(DropStmt);
-                                       n->removeType = OBJECT_RULE;
-                                       n->objects = list_make1(lappend($7, makeString($5)));
-                                       n->behavior = $8;
-                                       n->missing_ok = true;
-                                       n->concurrent = false;
-                                       $$ = (Node *) n;
-                               }
-               ;
-
-
 /*****************************************************************************
  *
  *             QUERY: