Refactor handling of "-only" options in pg_dump, pg_restore - Mailing list pgsql-hackers

From jian he
Subject Refactor handling of "-only" options in pg_dump, pg_restore
Date
Msg-id CACJufxHDYn+3-2jR_kwYB0U7UrNP+0EPvAWzBBD5EfUzzr1uiw@mail.gmail.com
Whole thread
Responses Re: Refactor handling of "-only" options in pg_dump, pg_restore
Re: Refactor handling of "-only" options in pg_dump, pg_restore
List 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



--
jian
https://www.enterprisedb.com/

Attachment

pgsql-hackers by date:

Previous
From: shveta malik
Date:
Subject: Re: Skipping schema changes in publication
Next
From: Tatsuo Ishii
Date:
Subject: Re: Row pattern recognition