Currently, pg_dump dumps foreign options in a single line, for example

CREATE SERVER cluster FOREIGN DATA WRAPPER plproxy OPTIONS (p0 'host=host0', p1 
'host=host1', p2 'host=host2', p3 'host=host3');

I think it would be nicer if it looked more like this:

CREATE SERVER cluster FOREIGN DATA WRAPPER plproxy OPTIONS (
    p0 'host=host0',
    p1 'host=host1',
    p2 'host=host2',
    p3 'host=host3'
);

Attached is a patch to implement that, and a test file to play around
with.
diff --git i/src/bin/pg_dump/pg_dump.c w/src/bin/pg_dump/pg_dump.c
index afeae6f..6dd4895 100644
--- i/src/bin/pg_dump/pg_dump.c
+++ w/src/bin/pg_dump/pg_dump.c
@@ -5671,7 +5671,7 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
 							  "SELECT pg_catalog.quote_ident(option_name) || "
 							  "' ' || pg_catalog.quote_literal(option_value) "
 							  "FROM pg_catalog.pg_options_to_table(attfdwoptions)"
-							  "), ', ') AS attfdwoptions "
+							  "), E',\n    ') AS attfdwoptions "
 			 "FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_type t "
 							  "ON a.atttypid = t.oid "
 							  "WHERE a.attrelid = '%u'::pg_catalog.oid "
@@ -6488,7 +6488,7 @@ getForeignDataWrappers(int *numForeignDataWrappers)
 						  "SELECT quote_ident(option_name) || ' ' || "
 						  "quote_literal(option_value) "
 						  "FROM pg_options_to_table(fdwoptions)"
-						  "), ', ') AS fdwoptions "
+						  "), E',\n    ') AS fdwoptions "
 						  "FROM pg_foreign_data_wrapper",
 						  username_subquery);
 	}
@@ -6502,7 +6502,7 @@ getForeignDataWrappers(int *numForeignDataWrappers)
 						  "SELECT quote_ident(option_name) || ' ' || "
 						  "quote_literal(option_value) "
 						  "FROM pg_options_to_table(fdwoptions)"
-						  "), ', ') AS fdwoptions "
+						  "), E',\n    ') AS fdwoptions "
 						  "FROM pg_foreign_data_wrapper",
 						  username_subquery);
 	}
@@ -6591,7 +6591,7 @@ getForeignServers(int *numForeignServers)
 					  "SELECT quote_ident(option_name) || ' ' || "
 					  "quote_literal(option_value) "
 					  "FROM pg_options_to_table(srvoptions)"
-					  "), ', ') AS srvoptions "
+					  "), E',\n    ') AS srvoptions "
 					  "FROM pg_foreign_server",
 					  username_subquery);
 
@@ -11484,7 +11484,7 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
 		appendPQExpBuffer(q, " VALIDATOR %s", fdwinfo->fdwvalidator);
 
 	if (strlen(fdwinfo->fdwoptions) > 0)
-		appendPQExpBuffer(q, " OPTIONS (%s)", fdwinfo->fdwoptions);
+		appendPQExpBuffer(q, " OPTIONS (\n    %s\n)", fdwinfo->fdwoptions);
 
 	appendPQExpBuffer(q, ";\n");
 
@@ -11588,7 +11588,7 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo)
 	appendPQExpBuffer(q, "%s", fmtId(fdwname));
 
 	if (srvinfo->srvoptions && strlen(srvinfo->srvoptions) > 0)
-		appendPQExpBuffer(q, " OPTIONS (%s)", srvinfo->srvoptions);
+		appendPQExpBuffer(q, " OPTIONS (\n    %s\n)", srvinfo->srvoptions);
 
 	appendPQExpBuffer(q, ";\n");
 
@@ -11679,7 +11679,7 @@ dumpUserMappings(Archive *fout,
 					  "SELECT quote_ident(option_name) || ' ' || "
 					  "quote_literal(option_value) "
 					  "FROM pg_options_to_table(umoptions)"
-					  "), ', ') AS umoptions "
+					  "), E',\n    ') AS umoptions "
 					  "FROM pg_user_mappings "
 					  "WHERE srvid = '%u'",
 					  catalogId.oid);
@@ -11704,7 +11704,7 @@ dumpUserMappings(Archive *fout,
 		appendPQExpBuffer(q, " SERVER %s", fmtId(servername));
 
 		if (umoptions && strlen(umoptions) > 0)
-			appendPQExpBuffer(q, " OPTIONS (%s)", umoptions);
+			appendPQExpBuffer(q, " OPTIONS (\n    %s\n)", umoptions);
 
 		appendPQExpBuffer(q, ";\n");
 
@@ -12337,7 +12337,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
 							  "SELECT pg_catalog.quote_ident(option_name) || "
 							  "' ' || pg_catalog.quote_literal(option_value) "
 							  "FROM pg_catalog.pg_options_to_table(ftoptions)"
-							  "), ', ') AS ftoptions "
+							  "), E',\n    ') AS ftoptions "
 							  "FROM pg_catalog.pg_foreign_table ft "
 							  "JOIN pg_catalog.pg_foreign_server fs "
 							  "ON (fs.oid = ft.ftserver) "
@@ -12566,7 +12566,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
 
 		/* Dump generic options if any */
 		if (ftoptions && ftoptions[0])
-			appendPQExpBuffer(q, "\nOPTIONS (%s)", ftoptions);
+			appendPQExpBuffer(q, "\nOPTIONS (\n    %s\n)", ftoptions);
 
 		appendPQExpBuffer(q, ";\n");
 
@@ -12766,7 +12766,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
 								  fmtId(tbinfo->dobj.name));
 				appendPQExpBuffer(q, "ALTER COLUMN %s ",
 								  fmtId(tbinfo->attnames[j]));
-				appendPQExpBuffer(q, "OPTIONS (%s);\n",
+				appendPQExpBuffer(q, "OPTIONS (\n    %s\n);\n",
 								  tbinfo->attfdwoptions[j]);
 			}
 		}
CREATE FOREIGN DATA WRAPPER plproxy OPTIONS (
    query_timeout '1800'
);

CREATE SERVER cluster FOREIGN DATA WRAPPER plproxy OPTIONS (
    p0 'host=host0',
    p1 'host=host1',
    p2 'host=host2',
    p3 'host=host3'
);

CREATE USER MAPPING FOR peter SERVER cluster OPTIONS (
    user 'peter',
    password 'sekret'
);

CREATE FOREIGN DATA WRAPPER foo;

CREATE SERVER foo FOREIGN DATA WRAPPER foo;

CREATE FOREIGN TABLE foobar (a int, b text) SERVER foo OPTIONS (
    bar 'bar',
    baz 'baz'
);

ALTER FOREIGN TABLE foobar ALTER COLUMN a OPTIONS (abc 'def');
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to