>From 323b7e0a07a5467e7f8a6fe54769392eabbb639b Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Sat, 14 Feb 2015 15:37:57 -0300 Subject: [PATCH 36/42] deparse: support CREATE SERVER --- src/backend/tcop/deparse_utility.c | 41 +++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/backend/tcop/deparse_utility.c b/src/backend/tcop/deparse_utility.c index cd600ff..c4ec7c0 100644 --- a/src/backend/tcop/deparse_utility.c +++ b/src/backend/tcop/deparse_utility.c @@ -1748,6 +1748,45 @@ deparse_AlterExtensionStmt(Oid objectId, Node *parsetree) return stmt; } +static ObjTree * +deparse_CreateForeignServerStmt(Oid objectId, Node *parsetree) +{ + CreateForeignServerStmt *node = (CreateForeignServerStmt *) parsetree; + ObjTree *createServer; + ObjTree *tmp; + + createServer = new_objtree_VA("CREATE SERVER %{identity}I %{type}s %{version}s " + "FOREIGN DATA WRAPPER %{fdw}I %{options}s", 2, + "identity", ObjTypeString, node->servername, + "fdw", ObjTypeString, node->fdwname); + + /* add a TYPE clause, if any */ + tmp = new_objtree_VA("TYPE %{type}L", 0); + if (node->servertype) + append_string_object(tmp, "type", node->servertype); + else + append_bool_object(tmp, "present", false); + append_object_object(createServer, "type", tmp); + + /* add a VERSION clause, if any */ + tmp = new_objtree_VA("VERSION %{version}L", 0); + if (node->version) + append_string_object(tmp, "version", node->version); + else + append_bool_object(tmp, "present", false); + append_object_object(createServer, "version", tmp); + + /* add an OPTIONS clause, if any */ + tmp = new_objtree_VA("OPTIONS (%{option:, }s)", 0); + if (node->options) + elog(ERROR, "unimplemented deparse of CREATE SERVER ... OPTIONS"); + else + append_bool_object(tmp, "present", false); + append_object_object(createServer, "options", tmp); + + return createServer; +} + /* * deparse_ViewStmt * deparse a ViewStmt @@ -5436,7 +5475,7 @@ deparse_simple_command(StashedCommand *cmd) break; case T_CreateForeignServerStmt: - elog(ERROR, "unimplemented deparse of %s", CreateCommandTag(parsetree)); + command = deparse_CreateForeignServerStmt(objectId, parsetree); break; case T_AlterForeignServerStmt: -- 2.1.4