@@ -97,6 +97,7 @@ main(int argc, char *argv[])
9797 static struct option long_options [] = {
9898 {"data-only" , no_argument , NULL , 'a' },
9999 {"clean" , no_argument , NULL , 'c' },
100+ {"encoding" , required_argument , NULL , 'E' },
100101 {"file" , required_argument , NULL , 'f' },
101102 {"globals-only" , no_argument , NULL , 'g' },
102103 {"host" , required_argument , NULL , 'h' },
@@ -147,6 +148,7 @@ main(int argc, char *argv[])
147148 char * pguser = NULL ;
148149 char * pgdb = NULL ;
149150 char * use_role = NULL ;
151+ const char * dumpencoding = NULL ;
150152 trivalue prompt_password = TRI_DEFAULT ;
151153 bool data_only = false;
152154 bool globals_only = false;
@@ -204,7 +206,7 @@ main(int argc, char *argv[])
204206
205207 pgdumpopts = createPQExpBuffer ();
206208
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 )
208210 {
209211 switch (c )
210212 {
@@ -221,6 +223,12 @@ main(int argc, char *argv[])
221223 connstr = pg_strdup (optarg );
222224 break ;
223225
226+ case 'E' :
227+ dumpencoding = pg_strdup (optarg );
228+ appendPQExpBufferStr (pgdumpopts , " -E " );
229+ appendShellString (pgdumpopts , optarg );
230+ break ;
231+
224232 case 'f' :
225233 filename = pg_strdup (optarg );
226234 appendPQExpBufferStr (pgdumpopts , " -f " );
@@ -453,6 +461,19 @@ main(int argc, char *argv[])
453461 else
454462 OPF = stdout ;
455463
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+
456477 /*
457478 * Get the active encoding and the standard_conforming_strings setting, so
458479 * we know how to escape strings.
@@ -588,6 +609,7 @@ help(void)
588609 printf (_ ("\nOptions controlling the output content:\n" ));
589610 printf (_ (" -a, --data-only dump only the data, not the schema\n" ));
590611 printf (_ (" -c, --clean clean (drop) databases before recreating\n" ));
612+ printf (_ (" -E, --encoding=ENCODING dump the data in encoding ENCODING\n" ));
591613 printf (_ (" -g, --globals-only dump only global objects, no databases\n" ));
592614 printf (_ (" -o, --oids include OIDs in dump\n" ));
593615 printf (_ (" -O, --no-owner skip restoration of object ownership\n" ));
0 commit comments