Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oD4qP-00043r-PU for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Jul 2022 14:02:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oD4qM-0003lH-S6 for pgsql-hackers@arkaria.postgresql.org; Sun, 17 Jul 2022 14:01:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oD4qM-0003fw-CK for pgsql-hackers@lists.postgresql.org; Sun, 17 Jul 2022 14:01:58 +0000 Received: from mail-qv1-xf34.google.com ([2607:f8b0:4864:20::f34]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oD4qF-0007xH-Eh for pgsql-hackers@postgresql.org; Sun, 17 Jul 2022 14:01:57 +0000 Received: by mail-qv1-xf34.google.com with SMTP id mi10so7098832qvb.1 for ; Sun, 17 Jul 2022 07:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+niYRCzg6OVc3b5kaj9pNmx69x3rYwWwkODMRJIjblw=; b=BXE48yQq1IY25lczHnHhGz4JhY/3i+jqjamy54MFu23S5MCnjNG4AYqdAEjhuSKmOc iwJ/JE1i8uImuVAtPSZu7oD3xlcfJG6k15YzWpIR0oTtkjE3CnHwro/GMFzo4IGnygdG bvWrWJPR1VuCgslSIJRkxVudXakyogc6nA7W+X2Tgs7h4fKBgWvKuCsukBkdClpa8icd 3I/yhIlc61DWho/yp/sO0SxibOVgbpeBEpkVsh/eJNg7g3uG8bM9K8gLZnM7CjxmCi17 XBbnDh9ZOjJOZDA3LiQNBlydp1gg3CoHWUXP6xftGW43ePB6Sm53cHKfCV4AXqFomqQ1 tNhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+niYRCzg6OVc3b5kaj9pNmx69x3rYwWwkODMRJIjblw=; b=IIVh1Tw0ueUFN8i+AQlNszIgHovZaCejW4JaunQTv5WSwOh0s7RHpOBAWp2KBP7CR8 1zaz9YOmNw4oZvp6iDuh9XSzvS2nUBtn8CYOQObUAal0A0TGq4351l2aTZczvAQ8P5S7 DB8kfbGbjGeTK9tszgQmvhD6YbDR6XEFp9om+6xxxgw2GcFR7Po9xHHqziHGisJUtrGa WYhRhOdm26KbEZmyySCoSnc5QUzK+R5TdUXVhsLdGm8r5Mg8p/iy2/Nxyr8RgW3cE8DB 8S5K+TqCZk54WlgRBEooLKC/zsukCgtgGG2DBfAZcH1GTjW6eWJdGFQlYHVpXCIjWpNo POQg== X-Gm-Message-State: AJIora8Btsfn/asE9YH0unZtHfduO1eKvyVcrLmn8YGmH9jPbWsPqBqX 2SbTLkh619ppIhTlqK/iBL47CQ== X-Google-Smtp-Source: AGRyM1tVn8LS8nIEBo6bLsGZ2TwXoZyEmcWpXSjnUt/WOMe1vAxapulLWYFNibvxIV03VMYSqcqhVQ== X-Received: by 2002:a05:6214:19c8:b0:472:f250:2d97 with SMTP id j8-20020a05621419c800b00472f2502d97mr18025175qvc.13.1658066508366; Sun, 17 Jul 2022 07:01:48 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id ay31-20020a05620a179f00b006b5de51ec1asm3478269qkb.26.2022.07.17.07.01.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 17 Jul 2022 07:01:47 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 112038019D7; Sun, 17 Jul 2022 09:01:47 -0500 (CDT) Date: Sun, 17 Jul 2022 09:01:46 -0500 From: Justin Pryzby To: Pavel Stehule Cc: Andrew Dunstan , Daniel Gustafsson , Tom Lane , Alvaro Herrera , Tomas Vondra , Dean Rasheed , Stephen Frost , Surafel Temesgen , vignesh C , pgsql-hackers@postgresql.org Subject: Re: proposal: possibility to read dumped table's name from file Message-ID: <20220717140146.GY18011@telsasoft.com> References: <202107122259.n6o5uwb5erza@alvherre.pgsql> <3183720.1626131795@sss.pgh.pa.us> <7f9cde55-dd3b-a604-bf89-e70511025709@dunslane.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thanks for updating the patch. This failed to build on windows. http://cfbot.cputube.org/pavel-stehule.html 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 > > > > + > + > + > + > + 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: > + / for tables, > + / for schemas, > + for data on foreign servers and > + for table data. > + To read from STDIN use - as the STDIN comma > + > + Lines starting with # are considered comments and > + are ignored. Comments can be placed after filter as well. Blank lines change "are ignored" to "ignored", I think. > 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 > > > > + > + > + > + > + Specify a filename from which to read patterns for databases excluded > + from dump. The patterns are interpretted according to the same rules > + like . same rules *as* > + To read from STDIN use - as the comma > + filename. The 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" ? > 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 > > > > + > + > + > + > + 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 , , s/like/as/ > + , , > + or . > + To read from STDIN use - as the STDIN comma > +/* > + * filter_get_keyword - read the next filter keyword from buffer > + * > + * Search for keywords (limited to containing ascii alphabetic characters) in remove "containing" > + /* > + * 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" > + * The pattern is either simple without any whitespace, or properly quoted double space > + * in case there is whitespace in the object name. The pattern handling follows s/is/may be/ > + 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" ? > + > + 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. > 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 :(