| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Refactor handling of "-only" options in pg_dump, pg_restore |
| Date: | 2026-03-02 04:57:20 |
| Message-ID: | CACJufxHDYn+3-2jR_kwYB0U7UrNP+0EPvAWzBBD5EfUzzr1uiw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi.
-------------------------------<<<<<<<
/* reject conflicting "-only" options */
if (data_only && schema_only)
pg_fatal("options %s and %s cannot be used together",
"-s/--schema-only", "-a/--data-only");
if (schema_only && statistics_only)
pg_fatal("options %s and %s cannot be used together",
"-s/--schema-only", "--statistics-only");
if (data_only && statistics_only)
pg_fatal("options %s and %s cannot be used together",
"-a/--data-only", "--statistics-only");
/* reject conflicting "-only" options */
if (data_only && with_statistics)
pg_fatal("options %s and %s cannot be used together",
"-a/--data-only", "--statistics");
if (schema_only && with_statistics)
pg_fatal("options %s and %s cannot be used together",
"-s/--schema-only", "--statistics");
-------------------------------<<<<<<<
The above is from src/bin/pg_dump/pg_dump.c, this is too much.
We can just use two IF statements:
if (data_only && (schema_only || with_statistics || statistics_only))
pg_fatal("options %s and %s cannot be used together",
"-a/--data-only",
schema_only ? "-s/--schema-only" :
with_statistics ? "--statistics" :
"--statistics-only");
if (schema_only && (with_statistics || statistics_only))
pg_fatal("options %s and %s cannot be used together",
"-s/--schema-only",
with_statistics ? "--statistics" :
"--statistics-only");
First "if (data_only && (schema_only" implies that the second IF check
won't have a combination
of `` if (schema_only && (data_only``.
Maybe we can use ELSE IF here.
We can do the same thing for pg_restore.c
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-pg_dump-pg_restore-refactor-only-option-error-check.patch | text/x-patch | 5.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tatsuo Ishii | 2026-03-02 05:18:23 | Re: Row pattern recognition |
| Previous Message | shveta malik | 2026-03-02 04:46:25 | Re: Skipping schema changes in publication |