Hello.

I noticed what I think is a bug in pg_dump.

When dumping foreign tables, the server name is not properly quoted,
which leads to unrestorable dumps.

eg, a foreign table attached to a foreign server named "file-test" is
dumped as:

CREATE FOREIGN TABLE "test-table" (
    col1 integer
)
SERVER file-test
OPTIONS (filename '/tmp/test');


Please look at the attached test case and the proposed patch.

Thank you.

-- 
Ronan Dunklau
create database test_dump_foreign_server;
\connect test_dump_foreign_server ;
create extension file_fdw;
create  server "file-test" foreign data wrapper file_fdw;
create foreign table "test-table" (col1 integer) server "file-test" options (filename '/tmp/test');



diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index ec932e4..1068b6a 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -12303,7 +12303,8 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
 
 			/* retrieve name of foreign server and generic options */
 			appendPQExpBuffer(query,
-							  "SELECT fs.srvname, array_to_string(ARRAY("
+							  "SELECT quote_ident(fs.srvname) as srvname,"
+								"array_to_string(ARRAY("
 				"   SELECT quote_ident(option_name) || ' ' || "
 				"          quote_literal(option_value)"
 			   "   FROM pg_options_to_table(ftoptions)), ', ') AS ftoptions "

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to