@@ -5667,11 +5667,11 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
5667
5667
"array_to_string(a.attoptions, ', ') AS attoptions, "
5668
5668
"CASE WHEN a.attcollation <> t.typcollation "
5669
5669
"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
+ "SELECT pg_catalog. quote_ident(option_name) || "
5672
+ "' ' || pg_catalog. quote_literal(option_value) "
5673
+ "FROM pg_catalog. pg_options_to_table(attfdwoptions)"
5674
+ "), ', ') AS attfdwoptions "
5675
5675
"FROM pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_type t "
5676
5676
"ON a.atttypid = t.oid "
5677
5677
"WHERE a.attrelid = '%u'::pg_catalog.oid "
@@ -6485,9 +6485,10 @@ getForeignDataWrappers(int *numForeignDataWrappers)
6485
6485
"fdwhandler::pg_catalog.regproc, "
6486
6486
"fdwvalidator::pg_catalog.regproc, fdwacl, "
6487
6487
"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 "
6491
6492
"FROM pg_foreign_data_wrapper" ,
6492
6493
username_subquery );
6493
6494
}
@@ -6498,9 +6499,10 @@ getForeignDataWrappers(int *numForeignDataWrappers)
6498
6499
"'-' AS fdwhandler, "
6499
6500
"fdwvalidator::pg_catalog.regproc, fdwacl, "
6500
6501
"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 "
6504
6506
"FROM pg_foreign_data_wrapper" ,
6505
6507
username_subquery );
6506
6508
}
@@ -6586,9 +6588,10 @@ getForeignServers(int *numForeignServers)
6586
6588
"(%s srvowner) AS rolname, "
6587
6589
"srvfdw, srvtype, srvversion, srvacl,"
6588
6590
"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 "
6592
6595
"FROM pg_foreign_server" ,
6593
6596
username_subquery );
6594
6597
@@ -11650,9 +11653,13 @@ dumpUserMappings(Archive *fout,
11650
11653
11651
11654
appendPQExpBuffer (query ,
11652
11655
"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 "
11654
11661
"FROM pg_user_mappings "
11655
- "WHERE srvid = %u " ,
11662
+ "WHERE srvid = '%u' " ,
11656
11663
catalogId .oid );
11657
11664
11658
11665
res = PQexec (g_conn , query -> data );
@@ -12212,12 +12219,12 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
12212
12219
int numParents ;
12213
12220
TableInfo * * parents ;
12214
12221
int actual_atts ; /* number of attrs in this CREATE statment */
12215
- char * reltypename ;
12222
+ const char * reltypename ;
12216
12223
char * storage ;
12224
+ char * srvname ;
12225
+ char * ftoptions ;
12217
12226
int j ,
12218
12227
k ;
12219
- char * srvname ;
12220
- char * ftoptions = NULL ;
12221
12228
12222
12229
/* Make sure we are in proper schema */
12223
12230
selectSourceSchema (tbinfo -> dobj .namespace -> dobj .name );
@@ -12303,15 +12310,25 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
12303
12310
12304
12311
/* retrieve name of foreign server and generic options */
12305
12312
appendPQExpBuffer (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 );
12313
12324
res = PQexec (g_conn , query -> data );
12314
12325
check_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
+ }
12315
12332
i_srvname = PQfnumber (res , "srvname" );
12316
12333
i_ftoptions = PQfnumber (res , "ftoptions" );
12317
12334
srvname = pg_strdup (PQgetvalue (res , 0 , i_srvname ));
@@ -12502,7 +12519,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
12502
12519
}
12503
12520
12504
12521
if (tbinfo -> relkind == RELKIND_FOREIGN_TABLE )
12505
- appendPQExpBuffer (q , "\nSERVER %s" , srvname );
12522
+ appendPQExpBuffer (q , "\nSERVER %s" , fmtId ( srvname ) );
12506
12523
12507
12524
if ((tbinfo -> reloptions && strlen (tbinfo -> reloptions ) > 0 ) ||
12508
12525
(tbinfo -> toast_reloptions && strlen (tbinfo -> toast_reloptions ) > 0 ))
0 commit comments