pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Davis <pgsql@j-davis.com>
To: Nathan Bossart <nathandbossart@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Peter Eisentraut <peter@eisentraut.org>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: pg_dump --with-* options
Date: Tue, 29 Jul 2025 11:13:14 -0700
Message-ID: <13a2cd63ec37d42b65bde5dadc39b61861e97cbc.camel@j-davis.com> (raw)
In-Reply-To: <8ce896d1a05040905cc1a3afbc04e94d8e95669a.camel@j-davis.com>
References: <7cc52488-f876-4ad3-affd-6e4b0ef0cb09@eisentraut.org>
	<aEMLzPQtjRbj2R7X@nathan>
	<CA+TgmoactJEUHeXuxHLKNXHzm6-XrQFigPur-4nHTMFSiSRkiQ@mail.gmail.com>
	<aErpuM6RXSlK1FBW@nathan>
	<7bf0246542713d80f12c738c1d365d1365750c18.camel@j-davis.com>
	<5e398522803da9bf3f9fc33ca43084ec21ab0fcd.camel@j-davis.com>
	<aFLenfMRS9jFINxq@nathan>
	<031558c60e84362898922caa6a90587e7fdf2a57.camel@j-davis.com>
	<8ce896d1a05040905cc1a3afbc04e94d8e95669a.camel@j-davis.com>

On Thu, 2025-07-10 at 10:42 -0700, Jeff Davis wrote:
> On Wed, 2025-06-18 at 10:21 -0700, Jeff Davis wrote:
> >   * reject the combination of an "only" option and a "with" option
> 
> There seems to be a rough consensus on this point.

Patch attached.

Regards,
	Jeff Davis

Attachments:

0001-pg_dump-reject-combination-of-only-and-with.patch (text/x-patch, 5.5K) download From f668a980ca73a608a9d00b9eff07667b3f8a7869 Mon Sep 17 00:00:00 2001 From: Jeff Davis <jeff@j-davis.com> Date: Tue, 29 Jul 2025 10:58:05 -0700 Subject: [PATCH] pg_dump: reject combination of "only" and "with" Discussion: https://postgr.es/m/8ce896d1a05040905cc1a3afbc04e94d8e95669a.camel@j-davis.com --- src/bin/pg_dump/pg_dump.c | 22 +++++++++++++++++----- src/bin/pg_dump/pg_restore.c | 22 +++++++++++++++++----- src/bin/pg_dump/t/002_pg_dump.pl | 18 +++++++++++------- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 6298edb26b5..1b19cd66008 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -860,6 +860,20 @@ main(int argc, char **argv) if (with_statistics && no_statistics) pg_fatal("options --with-statistics and --no-statistics cannot be used together"); + /* reject conflicting "only-" and "with-" options */ + if (data_only && with_schema) + pg_fatal("options -a/--data-only and --with-schema cannot be used together"); + if (data_only && with_statistics) + pg_fatal("options -a/--data-only and --with-statistics cannot be used together"); + if (schema_only && with_data) + pg_fatal("options -s/--schema-only and --with-data cannot be used together"); + if (schema_only && with_statistics) + pg_fatal("options -s/--schema-only and --with-statistics cannot be used together"); + if (statistics_only && with_data) + pg_fatal("options --statistics-only and --with-data cannot be used together"); + if (statistics_only && with_schema) + pg_fatal("options --statistics-only and --with-schema cannot be used together"); + if (schema_only && foreign_servers_include_patterns.head != NULL) pg_fatal("options -s/--schema-only and --include-foreign-data cannot be used together"); @@ -873,11 +887,9 @@ main(int argc, char **argv) pg_fatal("option --if-exists requires option -c/--clean"); /* - * Set derivative flags. An "-only" option may be overridden by an - * explicit "with-" option; e.g. "--schema-only --with-statistics" will - * include schema and statistics. Other ambiguous or nonsensical - * combinations, e.g. "--schema-only --no-schema", will have already - * caused an error in one of the checks above. + * Set derivative flags. Ambiguous or nonsensical combinations, + * e.g. "--schema-only --no-schema", will have already caused an error in + * one of the checks above. */ dopt.dumpData = ((dopt.dumpData && !schema_only && !statistics_only) || (data_only || with_data)) && !no_data; diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index 6ef789cb06d..4ca6c750bc7 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -425,6 +425,20 @@ main(int argc, char **argv) if (with_statistics && no_statistics) pg_fatal("options --with-statistics and --no-statistics cannot be used together"); + /* reject conflicting "only-" and "with-" options */ + if (data_only && with_schema) + pg_fatal("options -a/--data-only and --with-schema cannot be used together"); + if (data_only && with_statistics) + pg_fatal("options -a/--data-only and --with-statistics cannot be used together"); + if (schema_only && with_data) + pg_fatal("options -s/--schema-only and --with-data cannot be used together"); + if (schema_only && with_statistics) + pg_fatal("options -s/--schema-only and --with-statistics cannot be used together"); + if (statistics_only && with_data) + pg_fatal("options --statistics-only and --with-data cannot be used together"); + if (statistics_only && with_schema) + pg_fatal("options --statistics-only and --with-schema cannot be used together"); + if (data_only && opts->dropSchema) pg_fatal("options -c/--clean and -a/--data-only cannot be used together"); @@ -443,11 +457,9 @@ main(int argc, char **argv) pg_fatal("cannot specify both --single-transaction and multiple jobs"); /* - * Set derivative flags. An "-only" option may be overridden by an - * explicit "with-" option; e.g. "--schema-only --with-statistics" will - * include schema and statistics. Other ambiguous or nonsensical - * combinations, e.g. "--schema-only --no-schema", will have already - * caused an error in one of the checks above. + * Set derivative flags. Ambiguous or nonsensical combinations, + * e.g. "--schema-only --no-schema", will have already caused an error in + * one of the checks above. */ opts->dumpData = ((opts->dumpData && !schema_only && !statistics_only) || (data_only || with_data)) && !no_data; diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl index 6c7ec80e271..d597842908e 100644 --- a/src/bin/pg_dump/t/002_pg_dump.pl +++ b/src/bin/pg_dump/t/002_pg_dump.pl @@ -799,13 +799,6 @@ my %pgdump_runs = ( 'postgres', ], }, - schema_only_with_statistics => { - dump_cmd => [ - 'pg_dump', '--no-sync', - "--file=$tempdir/schema_only_with_statistics.sql", - '--schema-only', '--with-statistics', 'postgres', - ], - }, no_schema => { dump_cmd => [ 'pg_dump', '--no-sync', @@ -5207,6 +5200,17 @@ command_fails_like( qr/\Qpg_dump: error: no matching schemas were found for pattern\E/, 'no matching schemas'); +command_fails_like( + [ + 'pg_dump', + '--port' => $port, + '--strict-names', + '--schema-only', + '--with-statistics', + ], + qr/\Qpg_dump: error: options -s\/--schema-only and --with-statistics cannot be used together\E/, + 'cannot use --schema-only and --with-statistics together'); + command_fails_like( [ 'pg_dump', -- 2.43.0

view thread (72+ messages)  latest in thread

Message-ID: <13a2cd63ec37d42b65bde5dadc39b61861e97cbc.camel@j-davis.com>
Permalink:  ../13a2cd63ec37d42b65bde5dadc39b61861e97cbc.camel@j-davis.com/
Also on:    postgresql.org/message-id/13a2cd63ec37d42b65bde5dadc39b61861e97cbc.camel@j-davis.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: pgsql@j-davis.com, nathandbossart@gmail.com, robertmhaas@gmail.com, peter@eisentraut.org
  Subject: Re: pg_dump --with-* options
  In-Reply-To: <13a2cd63ec37d42b65bde5dadc39b61861e97cbc.camel@j-davis.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox