On 12/08/2011 11:36 AM, Andrew Dunstan wrote:


On 12/08/2011 11:13 AM, Robert Haas wrote:
Ah, hmm.  Well, maybe it's fine the way that you have it.  But I'd be
tempted to at least add a sentence to the sgml documentation for each
option referring to the other, e.g. "To dump only schema for all
tables in the database, see --schema-only." and "To exclude table data
for only a subset of tables in the database, see
--exclude-table-data.", or something along those lines.


Sure, no problem with that.



Revised patch attached.

cheers

andrew
*** a/doc/src/sgml/ref/pg_dump.sgml
--- b/doc/src/sgml/ref/pg_dump.sgml
***************
*** 404,409 **** PostgreSQL documentation
--- 404,413 ----
         <para>
          Dump only the object definitions (schema), not data.
         </para>
+        <para>
+         To exclude table data for only a subset of tables in the database, 
+         see <option>--exclude-table-data</>.
+        </para>
        </listitem>
       </varlistentry>
  
***************
*** 612,617 **** PostgreSQL documentation
--- 616,639 ----
       </varlistentry>
  
       <varlistentry>
+       <term><option>--exclude-table-data=<replaceable class="parameter">table</replaceable></option></term>
+       <listitem>
+        <para>
+         Do not dump data for any tables matching the <replaceable
+         class="parameter">table</replaceable> pattern.  The pattern is
+         interpreted according to the same rules as for <option>-t</>.
+         <option>--exclude-table-data</> can be given more than once to 
+         exclude tables matching any of several patterns. This option is
+         useful when you need the definition of a particular table even
+         though you do not need the data in it.
+        </para>
+        <para>
+         To exclude data for all tables in the database, see <option>--schema-only</>.
+        <para>
+       </listitem>
+      </varlistentry>
+ 
+      <varlistentry>
        <term><option>--inserts</option></term>
        <listitem>
         <para>
*** a/src/bin/pg_dump/pg_dump.c
--- b/src/bin/pg_dump/pg_dump.c
***************
*** 115,120 **** static SimpleStringList table_include_patterns = {NULL, NULL};
--- 115,122 ----
  static SimpleOidList table_include_oids = {NULL, NULL};
  static SimpleStringList table_exclude_patterns = {NULL, NULL};
  static SimpleOidList table_exclude_oids = {NULL, NULL};
+ static SimpleStringList tabledata_exclude_patterns = {NULL, NULL};
+ static SimpleOidList tabledata_exclude_oids = {NULL, NULL};
  
  /* default, if no "inclusion" switches appear, is to dump everything */
  static bool include_everything = true;
***************
*** 324,329 **** main(int argc, char **argv)
--- 326,332 ----
  		{"column-inserts", no_argument, &column_inserts, 1},
  		{"disable-dollar-quoting", no_argument, &disable_dollar_quoting, 1},
  		{"disable-triggers", no_argument, &disable_triggers, 1},
+ 		{"exclude-table-data", required_argument, NULL, 4},
  		{"inserts", no_argument, &dump_inserts, 1},
  		{"lock-wait-timeout", required_argument, NULL, 2},
  		{"no-tablespaces", no_argument, &outputNoTablespaces, 1},
***************
*** 487,492 **** main(int argc, char **argv)
--- 490,499 ----
  				use_role = optarg;
  				break;
  
+ 			case 4:			/* exclude table(s) data */
+ 				simple_string_list_append(&tabledata_exclude_patterns, optarg);
+ 				break;
+ 
  			default:
  				fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
  				exit(1);
***************
*** 715,720 **** main(int argc, char **argv)
--- 722,731 ----
  	}
  	expand_table_name_patterns(&table_exclude_patterns,
  							   &table_exclude_oids);
+ 
+ 	expand_table_name_patterns(&tabledata_exclude_patterns,
+ 							   &tabledata_exclude_oids);
+ 
  	/* non-matching exclusion patterns aren't an error */
  
  	/*
***************
*** 854,859 **** help(const char *progname)
--- 865,871 ----
  	printf(_("  --column-inserts            dump data as INSERT commands with column names\n"));
  	printf(_("  --disable-dollar-quoting    disable dollar quoting, use SQL standard quoting\n"));
  	printf(_("  --disable-triggers          disable triggers during data-only restore\n"));
+ 	printf(_("  --exclude-table-data=TABLE  do NOT dump data for the named table(s)\n"));
  	printf(_("  --inserts                   dump data as INSERT commands, rather than COPY\n"));
  	printf(_("  --no-security-labels        do not dump security label assignments\n"));
  	printf(_("  --no-tablespaces            do not dump tablespace assignments\n"));
***************
*** 1087,1092 **** selectDumpableTable(TableInfo *tbinfo)
--- 1099,1113 ----
  		simple_oid_list_member(&table_exclude_oids,
  							   tbinfo->dobj.catId.oid))
  		tbinfo->dobj.dump = false;
+ 
+ 	/* If table is to be dumped, check that the data is not excluded */
+ 	if (tbinfo->dobj.dump && !
+ 		simple_oid_list_member(&tabledata_exclude_oids,
+ 							   tbinfo->dobj.catId.oid))
+ 		tbinfo->dobj.dumpdata = true;
+ 	else
+ 		tbinfo->dobj.dumpdata = false;
+ 		
  }
  
  /*
***************
*** 1518,1523 **** dumpTableData(Archive *fout, TableDataInfo *tdinfo)
--- 1539,1548 ----
  	DataDumperPtr dumpFn;
  	char	   *copyStmt;
  
+ 	/* don't do anything if the data isn't wanted */
+ 	if (!tbinfo->dobj.dumpdata)
+ 		return;
+ 
  	if (!dump_inserts)
  	{
  		/* Dump/restore using COPY */
*** a/src/bin/pg_dump/pg_dump.h
--- b/src/bin/pg_dump/pg_dump.h
***************
*** 129,134 **** typedef struct _dumpableObject
--- 129,135 ----
  	char	   *name;			/* object name (should never be NULL) */
  	struct _namespaceInfo *namespace;	/* containing namespace, or NULL */
  	bool		dump;			/* true if we want to dump this object */
+ 	bool        dumpdata;       /* true if we want data for this object */
  	bool		ext_member;		/* true if object is member of extension */
  	DumpId	   *dependencies;	/* dumpIds of objects this one depends on */
  	int			nDeps;			/* number of valid dependencies */
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to