Re: proposal: possibility to read dumped table's name from file - Mailing list pgsql-hackers
From | Pavel Stehule |
---|---|
Subject | Re: proposal: possibility to read dumped table's name from file |
Date | |
Msg-id | CAFj8pRDBvqsw=Y3UwLce=JRS9fce3Wg-r8YmxA6HzPqqM5sREA@mail.gmail.com Whole thread Raw |
In response to | Re: proposal: possibility to read dumped table's name from file (Justin Pryzby <pryzby@telsasoft.com>) |
Responses |
Re: proposal: possibility to read dumped table's name from file
|
List | pgsql-hackers |
ne 17. 7. 2022 v 16:01 odesílatel Justin Pryzby <pryzby@telsasoft.com> napsal:
Thanks for updating the patch.
This failed to build on windows.
http://cfbot.cputube.org/pavel-stehule.html
Yes, there was a significant problem with the function exit_nicely, that is differently implemented in pg_dump and pg_dumpall.
Some more comments inline.
On Sun, Jul 17, 2022 at 08:20:47AM +0200, Pavel Stehule wrote:
> The attached patch implements the --filter option for pg_dumpall and for
> pg_restore too.
> diff --git a/doc/src/sgml/ref/pg_dump.sgml b/doc/src/sgml/ref/pg_dump.sgml
> index 5efb442b44..ba2920dbee 100644
> --- a/doc/src/sgml/ref/pg_dump.sgml
> +++ b/doc/src/sgml/ref/pg_dump.sgml
> @@ -779,6 +779,80 @@ PostgreSQL documentation
> </listitem>
> </varlistentry>
>
> + <varlistentry>
> + <term><option>--filter=<replaceable class="parameter">filename</replaceable></option></term>
> + <listitem>
> + <para>
> + Specify a filename from which to read patterns for objects to include
> + or exclude from the dump. The patterns are interpreted according to the
> + same rules as the corresponding options:
> + <option>-t</option>/<option>--table</option> for tables,
> + <option>-n</option>/<option>--schema</option> for schemas,
> + <option>--include-foreign-data</option> for data on foreign servers and
> + <option>--exclude-table-data</option> for table data.
> + To read from <literal>STDIN</literal> use <filename>-</filename> as the
STDIN comma
fixed
> + <para>
> + Lines starting with <literal>#</literal> are considered comments and
> + are ignored. Comments can be placed after filter as well. Blank lines
change "are ignored" to "ignored", I think.
changed
> diff --git a/doc/src/sgml/ref/pg_dumpall.sgml b/doc/src/sgml/ref/pg_dumpall.sgml
> index 8a081f0080..137491340c 100644
> --- a/doc/src/sgml/ref/pg_dumpall.sgml
> +++ b/doc/src/sgml/ref/pg_dumpall.sgml
> @@ -122,6 +122,29 @@ PostgreSQL documentation
> </listitem>
> </varlistentry>
>
> + <varlistentry>
> + <term><option>--filter=<replaceable class="parameter">filename</replaceable></option></term>
> + <listitem>
> + <para>
> + Specify a filename from which to read patterns for databases excluded
> + from dump. The patterns are interpretted according to the same rules
> + like <option>--exclude-database</option>.
same rules *as*
fixed
> + To read from <literal>STDIN</literal> use <filename>-</filename> as the
comma
fixed
> + filename. The <option>--filter</option> option can be specified in
> + conjunction with the above listed options for including or excluding
For dumpall, remove "for including or"
change "above listed options" to "exclude-database" ?
fixed
> diff --git a/doc/src/sgml/ref/pg_restore.sgml b/doc/src/sgml/ref/pg_restore.sgml
> index 526986eadb..5f16c4a333 100644
> --- a/doc/src/sgml/ref/pg_restore.sgml
> +++ b/doc/src/sgml/ref/pg_restore.sgml
> @@ -188,6 +188,31 @@ PostgreSQL documentation
> </listitem>
> </varlistentry>
>
> + <varlistentry>
> + <term><option>--filter=<replaceable class="parameter">filename</replaceable></option></term>
> + <listitem>
> + <para>
> + Specify a filename from which to read patterns for objects excluded
> + or included from restore. The patterns are interpretted according to the
> + same rules like <option>--schema</option>, <option>--exclude-schema</option>,
s/like/as/
changed
> + <option>--function</option>, <option>--index</option>, <option>--table</option>
> + or <option>--trigger</option>.
> + To read from <literal>STDIN</literal> use <filename>-</filename> as the
STDIN comma
fixed
> +/*
> + * filter_get_keyword - read the next filter keyword from buffer
> + *
> + * Search for keywords (limited to containing ascii alphabetic characters) in
remove "containing"
fixed
> + /*
> + * If the object name pattern has been quoted we must take care parse out
> + * the entire quoted pattern, which may contain whitespace and can span
> + * over many lines.
quoted comma
*to parse
remove "over"
fixed
> + * The pattern is either simple without any whitespace, or properly quoted
double space
fixed
> + * in case there is whitespace in the object name. The pattern handling follows
s/is/may be/
fixed
> + if (size == 7 && pg_strncasecmp(keyword, "include", 7) == 0)
> + *is_include = true;
> + else if (size == 7 && pg_strncasecmp(keyword, "exclude", 7) == 0)
> + *is_include = false;
Can't you write strncasecmp(keyword, "include", size) to avoid hardcoding "7" ?
I need to compare the size of the keyword with expected size, but I can use strlen(conststr). I wrote new macro is_keyword_str to fix this issue
fixed
> +
> + if (size == 4 && pg_strncasecmp(keyword, "data", 4) == 0)
> + *objtype = FILTER_OBJECT_TYPE_DATA;
> + else if (size == 8 && pg_strncasecmp(keyword, "database", 8) == 0)
> + *objtype = FILTER_OBJECT_TYPE_DATABASE;
> + else if (size == 12 && pg_strncasecmp(keyword, "foreign_data", 12) == 0)
> + *objtype = FILTER_OBJECT_TYPE_FOREIGN_DATA;
> + else if (size == 8 && pg_strncasecmp(keyword, "function", 8) == 0)
> + *objtype = FILTER_OBJECT_TYPE_FUNCTION;
> + else if (size == 5 && pg_strncasecmp(keyword, "index", 5) == 0)
> + *objtype = FILTER_OBJECT_TYPE_INDEX;
> + else if (size == 6 && pg_strncasecmp(keyword, "schema", 6) == 0)
> + *objtype = FILTER_OBJECT_TYPE_SCHEMA;
> + else if (size == 5 && pg_strncasecmp(keyword, "table", 5) == 0)
> + *objtype = FILTER_OBJECT_TYPE_TABLE;
> + else if (size == 7 && pg_strncasecmp(keyword, "trigger", 7) == 0)
> + *objtype = FILTER_OBJECT_TYPE_TRIGGER;
Avoid hardcoding these constants.
fixed
> diff --git a/src/bin/pg_dump/filter.h b/src/bin/pg_dump/filter.h
> new file mode 100644
> index 0000000000..e4a1a74b10
> --- /dev/null
> +++ b/src/bin/pg_dump/filter.h
...
> \ No newline at end of file
fixed
updated patch attached
Regards
Pavel
:(
Attachment
pgsql-hackers by date: