From: Abhijit Menon-Sen Date: Thu, 8 May 2014 10:05:58 +0000 (+0530) Subject: deparse: Support ALTER EXTENSION / UPDATE TO X-Git-Tag: deparse-before-rebase-20150215~84 X-Git-Url: http://git.postgresql.org/gitweb/static/%7B%7Bpguslink%28?a=commitdiff_plain;h=58fb60d8d05afee0968774f987e88c12d891ac03;p=2ndquadrant_bdr.git deparse: Support ALTER EXTENSION / UPDATE TO --- diff --git a/src/backend/tcop/deparse_utility.c b/src/backend/tcop/deparse_utility.c index 05a481e4d2..c91fc9b544 100644 --- a/src/backend/tcop/deparse_utility.c +++ b/src/backend/tcop/deparse_utility.c @@ -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: