@@ -97,6 +97,7 @@ main(int argc, char *argv[])
97
97
static struct option long_options [] = {
98
98
{"data-only" , no_argument , NULL , 'a' },
99
99
{"clean" , no_argument , NULL , 'c' },
100
+ {"encoding" , required_argument , NULL , 'E' },
100
101
{"file" , required_argument , NULL , 'f' },
101
102
{"globals-only" , no_argument , NULL , 'g' },
102
103
{"host" , required_argument , NULL , 'h' },
@@ -147,6 +148,7 @@ main(int argc, char *argv[])
147
148
char * pguser = NULL ;
148
149
char * pgdb = NULL ;
149
150
char * use_role = NULL ;
151
+ const char * dumpencoding = NULL ;
150
152
trivalue prompt_password = TRI_DEFAULT ;
151
153
bool data_only = false;
152
154
bool globals_only = false;
@@ -204,7 +206,7 @@ main(int argc, char *argv[])
204
206
205
207
pgdumpopts = createPQExpBuffer ();
206
208
207
- while ((c = getopt_long (argc , argv , "acd:f:gh:l:oOp:rsS:tU:vwWx" , long_options , & optindex )) != -1 )
209
+ while ((c = getopt_long (argc , argv , "acd:E: f:gh:l:oOp:rsS:tU:vwWx" , long_options , & optindex )) != -1 )
208
210
{
209
211
switch (c )
210
212
{
@@ -221,6 +223,12 @@ main(int argc, char *argv[])
221
223
connstr = pg_strdup (optarg );
222
224
break ;
223
225
226
+ case 'E' :
227
+ dumpencoding = pg_strdup (optarg );
228
+ appendPQExpBufferStr (pgdumpopts , " -E " );
229
+ appendShellString (pgdumpopts , optarg );
230
+ break ;
231
+
224
232
case 'f' :
225
233
filename = pg_strdup (optarg );
226
234
appendPQExpBufferStr (pgdumpopts , " -f " );
@@ -453,6 +461,19 @@ main(int argc, char *argv[])
453
461
else
454
462
OPF = stdout ;
455
463
464
+ /*
465
+ * Set the client encoding if requested.
466
+ */
467
+ if (dumpencoding )
468
+ {
469
+ if (PQsetClientEncoding (conn , dumpencoding ) < 0 )
470
+ {
471
+ fprintf (stderr , _ ("%s: invalid client encoding \"%s\" specified\n" ),
472
+ progname , dumpencoding );
473
+ exit_nicely (1 );
474
+ }
475
+ }
476
+
456
477
/*
457
478
* Get the active encoding and the standard_conforming_strings setting, so
458
479
* we know how to escape strings.
@@ -588,6 +609,7 @@ help(void)
588
609
printf (_ ("\nOptions controlling the output content:\n" ));
589
610
printf (_ (" -a, --data-only dump only the data, not the schema\n" ));
590
611
printf (_ (" -c, --clean clean (drop) databases before recreating\n" ));
612
+ printf (_ (" -E, --encoding=ENCODING dump the data in encoding ENCODING\n" ));
591
613
printf (_ (" -g, --globals-only dump only global objects, no databases\n" ));
592
614
printf (_ (" -o, --oids include OIDs in dump\n" ));
593
615
printf (_ (" -O, --no-owner skip restoration of object ownership\n" ));
0 commit comments