deparse: Support ALTER EXTENSION / UPDATE TO
authorAbhijit Menon-Sen <ams@2ndQuadrant.com>
Thu, 8 May 2014 10:05:58 +0000 (15:35 +0530)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 13 Oct 2014 03:19:49 +0000 (00:19 -0300)
src/backend/tcop/deparse_utility.c

index 05a481e4d24aea200a4a8c0adfd03a0256cfbb96..c91fc9b544dd65b899c7f3a74f0c7e4525c603e7 100644 (file)
@@ -1496,6 +1496,48 @@ deparse_CreateExtensionStmt(Oid objectId, Node *parsetree)
    return extStmt;
 }
 
+static ObjTree *
+deparse_AlterExtensionStmt(Oid objectId, Node *parsetree)
+{
+   AlterExtensionStmt *node = (AlterExtensionStmt *) parsetree;
+   Relation    pg_extension;
+   HeapTuple   extTup;
+   Form_pg_extension extForm;
+   ObjTree    *stmt;
+   char       *version = NULL;
+   ListCell   *cell;
+
+   pg_extension = heap_open(ExtensionRelationId, AccessShareLock);
+   extTup = get_catalog_object_by_oid(pg_extension, objectId);
+   if (!HeapTupleIsValid(extTup))
+       elog(ERROR, "cache lookup failed for extension with OID %u",
+            objectId);
+   extForm = (Form_pg_extension) GETSTRUCT(extTup);
+
+   stmt = new_objtree_VA("ALTER EXTENSION %{identity}I UPDATE%{to}s", 1,
+                         "identity", ObjTypeString,
+                         NameStr(extForm->extname));
+
+   foreach(cell, node->options)
+   {
+       DefElem *opt = (DefElem *) lfirst(cell);
+
+       if (strcmp(opt->defname, "new_version") == 0)
+           version = defGetString(opt);
+       else
+           elog(ERROR, "unsupported option %s", opt->defname);
+   }
+
+   if (version)
+       append_string_object(stmt, "to", psprintf(" TO '%s'", version));
+   else
+       append_string_object(stmt, "to", "");
+
+   heap_close(pg_extension, AccessShareLock);
+
+   return stmt;
+}
+
 /*
  * deparse_ViewStmt
  *     deparse a ViewStmt
@@ -4135,7 +4177,7 @@ deparse_simple_command(StashedCommand *cmd)
            break;
 
        case T_AlterExtensionStmt:
-           command = NULL;
+           command = deparse_AlterExtensionStmt(objectId, parsetree);
            break;
 
        case T_AlterExtensionContentsStmt: