Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6012189

Browse files
committed
pg_dump: reject combination of "only" and "with"
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>Discussion:https://postgr.es/m/8ce896d1a05040905cc1a3afbc04e94d8e95669a.camel@j-davis.comBackpatch-through: 18
1 parent42b1480 commit6012189

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

‎src/bin/pg_dump/pg_dump.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,17 @@ main(int argc, char **argv)
852852
if (with_statistics && no_statistics)
853853
pg_fatal("options --with-statistics and --no-statistics cannot be used together");
854854

855+
/* reject conflicting "-only" and "with-" options */
856+
if (data_only && (with_schema || with_statistics))
857+
pg_fatal("options %s and %s cannot be used together",
858+
"-a/--data-only", with_schema ? "--with-schema" : "--with-statistics");
859+
if (schema_only && (with_data || with_statistics))
860+
pg_fatal("options %s and %s cannot be used together",
861+
"-s/--schema-only", with_data ? "--with-data" : "--with-statistics");
862+
if (statistics_only && (with_data || with_schema))
863+
pg_fatal("options %s and %s cannot be used together",
864+
"--statistics-only", with_data ? "--with-data" : "--with-schema");
865+
855866
if (schema_only && foreign_servers_include_patterns.head != NULL)
856867
pg_fatal("options -s/--schema-only and --include-foreign-data cannot be used together");
857868

@@ -865,11 +876,9 @@ main(int argc, char **argv)
865876
pg_fatal("option --if-exists requires option -c/--clean");
866877

867878
/*
868-
* Set derivative flags. An "-only" option may be overridden by an
869-
* explicit "with-" option; e.g. "--schema-only --with-statistics" will
870-
* include schema and statistics. Other ambiguous or nonsensical
871-
* combinations, e.g. "--schema-only --no-schema", will have already
872-
* caused an error in one of the checks above.
879+
* Set derivative flags. Ambiguous or nonsensical combinations, e.g.
880+
* "--schema-only --no-schema", will have already caused an error in one
881+
* of the checks above.
873882
*/
874883
dopt.dumpData = ((dopt.dumpData && !schema_only && !statistics_only) ||
875884
(data_only || with_data)) && !no_data;

‎src/bin/pg_dump/pg_restore.c‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,17 @@ main(int argc, char **argv)
381381
if (with_statistics&&no_statistics)
382382
pg_fatal("options --with-statistics and --no-statistics cannot be used together");
383383

384+
/* reject conflicting "only-" and "with-" options */
385+
if (data_only&& (with_schema||with_statistics))
386+
pg_fatal("options %s and %s cannot be used together",
387+
"-a/--data-only",with_schema ?"--with-schema" :"--with-statistics");
388+
if (schema_only&& (with_data||with_statistics))
389+
pg_fatal("options %s and %s cannot be used together",
390+
"-s/--schema-only",with_data ?"--with-data" :"--with-statistics");
391+
if (statistics_only&& (with_data||with_schema))
392+
pg_fatal("options %s and %s cannot be used together",
393+
"--statistics-only",with_data ?"--with-data" :"--with-schema");
394+
384395
if (data_only&&opts->dropSchema)
385396
pg_fatal("options -c/--clean and -a/--data-only cannot be used together");
386397

@@ -399,11 +410,9 @@ main(int argc, char **argv)
399410
pg_fatal("cannot specify both --single-transaction and multiple jobs");
400411

401412
/*
402-
* Set derivative flags. An "-only" option may be overridden by an
403-
* explicit "with-" option; e.g. "--schema-only --with-statistics" will
404-
* include schema and statistics. Other ambiguous or nonsensical
405-
* combinations, e.g. "--schema-only --no-schema", will have already
406-
* caused an error in one of the checks above.
413+
* Set derivative flags. Ambiguous or nonsensical combinations, e.g.
414+
* "--schema-only --no-schema", will have already caused an error in one
415+
* of the checks above.
407416
*/
408417
opts->dumpData= ((opts->dumpData&& !schema_only&& !statistics_only)||
409418
(data_only||with_data))&& !no_data;

‎src/bin/pg_dump/t/002_pg_dump.pl‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -799,13 +799,6 @@
799799
'postgres',
800800
],
801801
},
802-
schema_only_with_statistics=> {
803-
dump_cmd=> [
804-
'pg_dump','--no-sync',
805-
"--file=$tempdir/schema_only_with_statistics.sql",
806-
'--schema-only','--with-statistics','postgres',
807-
],
808-
},
809802
no_schema=> {
810803
dump_cmd=> [
811804
'pg_dump','--no-sync',
@@ -5205,6 +5198,17 @@
52055198
qr/\Qpg_dump: error: no matching schemas were found for pattern\E/,
52065199
'no matching schemas');
52075200
5201+
command_fails_like(
5202+
[
5203+
'pg_dump',
5204+
'--port' =>$port,
5205+
'--strict-names',
5206+
'--schema-only',
5207+
'--with-statistics',
5208+
],
5209+
qr/\Qpg_dump: error: options -s\/--schema-only and --with-statistics cannot be used together\E/,
5210+
'cannot use --schema-only and --with-statistics together');
5211+
52085212
command_fails_like(
52095213
[
52105214
'pg_dump',

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp