@@ -5667,11 +5667,11 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
56675667"array_to_string(a.attoptions, ', ') AS attoptions, "
56685668"CASE WHEN a.attcollation <> t.typcollation "
56695669"THEN a.attcollation ELSE 0 END AS attcollation, "
5670- "array_to_string(ARRAY("
5671- " SELECT quote_ident(option_name) || ' ' || "
5672- " quote_literal(option_value) "
5673- " FROM pg_options_to_table(attfdwoptions)), ', ') "
5674- " AS attfdwoptions "
5670+ "pg_catalog. array_to_string(ARRAY("
5671+ "SELECTpg_catalog. quote_ident(option_name) || "
5672+ "' ' || pg_catalog. quote_literal(option_value) "
5673+ "FROMpg_catalog. pg_options_to_table(attfdwoptions)"
5674+ "), ', ') AS attfdwoptions "
56755675"FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_type t "
56765676"ON a.atttypid = t.oid "
56775677"WHERE a.attrelid = '%u'::pg_catalog.oid "
@@ -6485,9 +6485,10 @@ getForeignDataWrappers(int *numForeignDataWrappers)
64856485"fdwhandler::pg_catalog.regproc, "
64866486"fdwvalidator::pg_catalog.regproc, fdwacl, "
64876487"array_to_string(ARRAY("
6488- "SELECT quote_ident(option_name) || ' ' || "
6489- " quote_literal(option_value) "
6490- "FROM pg_options_to_table(fdwoptions)), ', ') AS fdwoptions "
6488+ "SELECT quote_ident(option_name) || ' ' || "
6489+ "quote_literal(option_value) "
6490+ "FROM pg_options_to_table(fdwoptions)"
6491+ "), ', ') AS fdwoptions "
64916492"FROM pg_foreign_data_wrapper" ,
64926493username_subquery );
64936494}
@@ -6498,9 +6499,10 @@ getForeignDataWrappers(int *numForeignDataWrappers)
64986499"'-' AS fdwhandler, "
64996500"fdwvalidator::pg_catalog.regproc, fdwacl, "
65006501"array_to_string(ARRAY("
6501- "SELECT quote_ident(option_name) || ' ' || "
6502- " quote_literal(option_value) "
6503- "FROM pg_options_to_table(fdwoptions)), ', ') AS fdwoptions "
6502+ "SELECT quote_ident(option_name) || ' ' || "
6503+ "quote_literal(option_value) "
6504+ "FROM pg_options_to_table(fdwoptions)"
6505+ "), ', ') AS fdwoptions "
65046506"FROM pg_foreign_data_wrapper" ,
65056507username_subquery );
65066508}
@@ -6586,9 +6588,10 @@ getForeignServers(int *numForeignServers)
65866588"(%s srvowner) AS rolname, "
65876589"srvfdw, srvtype, srvversion, srvacl,"
65886590"array_to_string(ARRAY("
6589- "SELECT quote_ident(option_name) || ' ' || "
6590- " quote_literal(option_value) "
6591- "FROM pg_options_to_table(srvoptions)), ', ') AS srvoptions "
6591+ "SELECT quote_ident(option_name) || ' ' || "
6592+ "quote_literal(option_value) "
6593+ "FROM pg_options_to_table(srvoptions)"
6594+ "), ', ') AS srvoptions "
65926595"FROM pg_foreign_server" ,
65936596username_subquery );
65946597
@@ -11650,9 +11653,13 @@ dumpUserMappings(Archive *fout,
1165011653
1165111654appendPQExpBuffer (query ,
1165211655"SELECT usename, "
11653- "array_to_string(ARRAY(SELECT quote_ident(option_name) || ' ' || quote_literal(option_value) FROM pg_options_to_table(umoptions)), ', ') AS umoptions\n"
11656+ "array_to_string(ARRAY("
11657+ "SELECT quote_ident(option_name) || ' ' || "
11658+ "quote_literal(option_value) "
11659+ "FROM pg_options_to_table(umoptions)"
11660+ "), ', ') AS umoptions "
1165411661"FROM pg_user_mappings "
11655- "WHERE srvid =%u " ,
11662+ "WHERE srvid ='%u' " ,
1165611663catalogId .oid );
1165711664
1165811665res = PQexec (g_conn ,query -> data );
@@ -12212,12 +12219,12 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1221212219int numParents ;
1221312220TableInfo * * parents ;
1221412221int actual_atts ;/* number of attrs in this CREATE statment */
12215- char * reltypename ;
12222+ const char * reltypename ;
1221612223char * storage ;
12224+ char * srvname ;
12225+ char * ftoptions ;
1221712226int j ,
1221812227k ;
12219- char * srvname ;
12220- char * ftoptions = NULL ;
1222112228
1222212229/* Make sure we are in proper schema */
1222312230selectSourceSchema (tbinfo -> dobj .namespace -> dobj .name );
@@ -12303,15 +12310,25 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1230312310
1230412311/* retrieve name of foreign server and generic options */
1230512312appendPQExpBuffer (query ,
12306- "SELECT fs.srvname, array_to_string(ARRAY("
12307- " SELECT quote_ident(option_name) || ' ' || "
12308- " quote_literal(option_value)"
12309- " FROM pg_options_to_table(ftoptions)), ', ') AS ftoptions "
12310- "FROM pg_foreign_table ft JOIN pg_foreign_server fs "
12311- "ON (fs.oid = ft.ftserver) "
12312- "WHERE ft.ftrelid = %u" ,tbinfo -> dobj .catId .oid );
12313+ "SELECT fs.srvname, "
12314+ "pg_catalog.array_to_string(ARRAY("
12315+ "SELECT pg_catalog.quote_ident(option_name) || "
12316+ "' ' || pg_catalog.quote_literal(option_value) "
12317+ "FROM pg_catalog.pg_options_to_table(ftoptions)"
12318+ "), ', ') AS ftoptions "
12319+ "FROM pg_catalog.pg_foreign_table ft "
12320+ "JOIN pg_catalog.pg_foreign_server fs "
12321+ "ON (fs.oid = ft.ftserver) "
12322+ "WHERE ft.ftrelid = '%u'" ,
12323+ tbinfo -> dobj .catId .oid );
1231312324res = PQexec (g_conn ,query -> data );
1231412325check_sql_result (res ,g_conn ,query -> data ,PGRES_TUPLES_OK );
12326+ if (PQntuples (res )!= 1 )
12327+ {
12328+ write_msg (NULL ,"query returned %d foreign server entries for foreign table \"%s\"\n" ,
12329+ PQntuples (res ),tbinfo -> dobj .name );
12330+ exit_nicely ();
12331+ }
1231512332i_srvname = PQfnumber (res ,"srvname" );
1231612333i_ftoptions = PQfnumber (res ,"ftoptions" );
1231712334srvname = pg_strdup (PQgetvalue (res ,0 ,i_srvname ));
@@ -12502,7 +12519,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
1250212519}
1250312520
1250412521if (tbinfo -> relkind == RELKIND_FOREIGN_TABLE )
12505- appendPQExpBuffer (q ,"\nSERVER %s" ,srvname );
12522+ appendPQExpBuffer (q ,"\nSERVER %s" ,fmtId ( srvname ) );
1250612523
1250712524if ((tbinfo -> reloptions && strlen (tbinfo -> reloptions )> 0 )||
1250812525 (tbinfo -> toast_reloptions && strlen (tbinfo -> toast_reloptions )> 0 ))