bdr: allow certain types of ALTER TABLE commands
authorChristian Kruse <[email protected]>
Wed, 2 Apr 2014 11:15:24 +0000 (13:15 +0200)
committerAndres Freund <[email protected]>
Thu, 3 Jul 2014 15:55:23 +0000 (17:55 +0200)
For now we allow:

- ADD COLUMN
- DEFAULT
- CLUSTER ON
- SET WITHOUT CLUSTER
- SET (...)
- RESET (...)
- replace reloption list

contrib/bdr/bdr_commandfilter.c

index 1b823c2c3dad528801e49fbbb7e306546c0947da..f4a85461606155da44bf58f9020d7e03503c06f4 100644 (file)
@@ -81,6 +81,7 @@ bdr_commandfilter(Node *parsetree,
    DropStmt   *dropStatement;
    RenameStmt *renameStatement;
    AlterTableStmt *alterTableStatement;
+   bool hasInvalid;
 
    ereport(DEBUG4,
         (errmsg_internal("bdr_commandfilter ProcessUtility_hook invoked")));
@@ -103,9 +104,39 @@ bdr_commandfilter(Node *parsetree,
             */
        case T_AlterTableStmt:
            alterTableStatement = (AlterTableStmt *) parsetree;
-           error_on_persistent_rv(alterTableStatement->relation,
-                                  "ALTER TABLE", AccessExclusiveLock,
-                                  severity, alterTableStatement->missing_ok);
+           hasInvalid = false;
+
+           foreach(cell, alterTableStatement->cmds)
+           {
+               AlterTableCmd *stmt = (AlterTableCmd *) lfirst(cell);
+
+               switch (stmt->subtype)
+               {
+                   /*
+                    * allowed for now:
+                    */
+                   case AT_AddColumn: /* add column */
+
+                   case AT_ColumnDefault: /* ALTER COLUMN DEFAULT */
+
+                   case AT_ClusterOn: /* CLUSTER ON */
+                   case AT_DropCluster: /* SET WITHOUT CLUSTER */
+
+                   case AT_SetRelOptions: /* SET (...) */
+                   case AT_ResetRelOptions: /* RESET (...) */
+                   case AT_ReplaceRelOptions: /* replace reloption list */
+                       break;
+
+                   default:
+                       hasInvalid = true;
+                       break;
+               }
+           }
+
+           if (hasInvalid)
+               error_on_persistent_rv(alterTableStatement->relation,
+                                      "ALTER TABLE", AccessExclusiveLock,
+                                      severity, alterTableStatement->missing_ok);
            break;
 
        case T_RenameStmt: