-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message
 
 
Attached is a patch to hopefully make pg_dump a lot more useful.
I started out by making it simply able to avoid dumping a single
table, but, inspired by David Fetter's patch last November, also
added in support for multiple items and limited wildcard matching.
 
-n and -N control the schemas, and -t and -T control the tables.
 
Wildcards can be a star at the start, the end, or on both sides
of a term. The patch acts inclusively with conflicts: the -t
option trumps the -N option.
 
Some examples:
 
To dump all tables beginning with the string "slony", plus
all tables with the word "log" inside of them:
 
pg_dump -t "slony*" -t "*log*"
 
To dump all schemas except "dev" and "qa", and all tables
except those ending in "large":
 
pg_dump -N "dev" -N "qa" -T "*large"
 
--
Greg Sabino Mullane [EMAIL PROTECTED]
PGP Key: 0x14964AC8 200601152100
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----
 
iD8DBQFDyv9NvJuQZxSWSsgRAup9AKD110JJtJBYYPV5JxFROovfeddrSACg3IZ3
BqczBImC8UCVmik3YFHvDeQ=
=Y9zs
-----END PGP SIGNATURE-----

Index: doc/src/sgml/ref/pg_dump.sgml
===================================================================
RCS file: /projects/cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v
retrieving revision 1.81
diff -c -r1.81 pg_dump.sgml
*** doc/src/sgml/ref/pg_dump.sgml	1 Nov 2005 21:09:50 -0000	1.81
--- doc/src/sgml/ref/pg_dump.sgml	16 Jan 2006 01:53:38 -0000
***************
*** 294,300 ****
         <para>
          Dump the contents of <replaceable class="parameter">schema</>
          only. If this option is not specified, all non-system schemas
!         in the target database will be dumped.
         </para>
  
         <note>
--- 294,302 ----
         <para>
          Dump the contents of <replaceable class="parameter">schema</>
          only. If this option is not specified, all non-system schemas
!         in the target database will be dumped. Can be set multiple times 
!         to dump more than one schema. Supports limited wildcards: you may 
!         put a star at the beginning and/or the end of the name.
         </para>
  
         <note>
***************
*** 310,315 ****
--- 312,330 ----
       </varlistentry>
  
       <varlistentry>
+       <term><option>-N <replaceable class="parameter">schema</replaceable></option></term>
+       <term><option>--exclude-schema=<replaceable class="parameter">schema</replaceable></option></term>
+       <listitem>
+        <para>
+         Do not dump the named <replaceable class="parameter">schema</>.
+         Can be set multiple times to exclude more than one schema. Supports limited 
+         wildcards: you may put a star at the beginning and/or the end of the name.
+         The -t argument is not affected by -N.
+        </para>
+       </listitem>
+      </varlistentry>
+ 
+      <varlistentry>
        <term><option>-o</></term>
        <term><option>--oids</></term>
        <listitem>
***************
*** 389,398 ****
        <listitem>
         <para>
          Dump data for <replaceable class="parameter">table</replaceable>
!         only. It is possible for there to be
!         multiple tables with the same name in different schemas; if that
!         is the case, all matching tables will be dumped.  Specify both
!         <option>--schema</> and <option>--table</> to select just one table.
         </para>
  
         <note>
--- 404,414 ----
        <listitem>
         <para>
          Dump data for <replaceable class="parameter">table</replaceable>
!         only. It is possible for there to be multiple tables with the same 
!         name in different schemas; if that is the case, all matching tables 
!         will be dumped, unless the -n option is used. Can be set multiple times 
!         to dump more than one table. Supports limited wildcards: you may put a 
!         star at the beginning and/or the end of the name.
         </para>
  
         <note>
***************
*** 408,413 ****
--- 424,444 ----
       </varlistentry>
  
       <varlistentry>
+       <term><option>-T <replaceable class="parameter">table</replaceable></option></term>
+       <term><option>--exclude-table=<replaceable class="parameter">table</replaceable></option></term>
+       <listitem>
+        <para>
+         Do not dump the named <replaceable class="parameter">table</replaceable>.
+         It is possible for there to be multiple tables with the same name in 
+         different schemas; if that is the case, all matching tables will be excluded.
+         Can be set multiple times to exclude more than one table. Supports limited 
+         wildcards: you may put a star at the beginning and/or the end of the name.
+         The -n argument is not affected by -T.
+        </para>
+       </listitem>
+      </varlistentry>
+ 
+      <varlistentry>
        <term><option>-v</></term>
        <term><option>--verbose</></term>
        <listitem>
***************
*** 672,677 ****
--- 703,732 ----
  </screen>
    </para>
  
+   <para>
+    To dump all schemas except those beginning with an underscore:
+ 
+ <screen>
+ <prompt>$</prompt> <userinput>pg_dump -N "_*" mydb &gt; db.out</userinput>
+ </screen>
+   </para>
+ 
+   <para>
+    To dump all tables ending in "log" or named "sales" in the schema "dev":
+ 
+ <screen>
+ <prompt>$</prompt> <userinput>pg_dump -t "*log" -t "sales" -n "dev" mydb &gt; db.out</userinput>
+ </screen>
+   </para>
+ 
+   <para>
+    To dump all tables with the letters "map" inside of their name:
+ 
+ <screen>
+ <prompt>$</prompt> <userinput>pg_dump -t "*map*" mydb &gt; db.out</userinput>
+ </screen>
+   </para>
+ 
   </refsect1>
  
   <refsect1>
Index: src/bin/pg_dump/common.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/common.c,v
retrieving revision 1.87
diff -c -r1.87 common.c
*** src/bin/pg_dump/common.c	15 Oct 2005 02:49:38 -0000	1.87
--- src/bin/pg_dump/common.c	16 Jan 2006 01:53:38 -0000
***************
*** 74,82 ****
   *	  Collect information about all potentially dumpable objects
   */
  TableInfo *
! getSchemaData(int *numTablesPtr,
! 			  const bool schemaOnly,
! 			  const bool dataOnly)
  {
  	NamespaceInfo *nsinfo;
  	AggInfo    *agginfo;
--- 74,80 ----
   *	  Collect information about all potentially dumpable objects
   */
  TableInfo *
! getSchemaData(int *numTablesPtr)
  {
  	NamespaceInfo *nsinfo;
  	AggInfo    *agginfo;
Index: src/bin/pg_dump/pg_dump.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.426
diff -c -r1.426 pg_dump.c
*** src/bin/pg_dump/pg_dump.c	9 Jan 2006 21:16:17 -0000	1.426
--- src/bin/pg_dump/pg_dump.c	16 Jan 2006 01:53:38 -0000
***************
*** 93,100 ****
  /* obsolete as of 7.3: */
  static Oid	g_last_builtin_oid; /* value of the last builtin oid */
  
! static char *selectTableName = NULL;	/* name of a single table to dump */
! static char *selectSchemaName = NULL;	/* name of a single schema to dump */
  
  char		g_opaque_type[10];	/* name for the opaque type */
  
--- 93,113 ----
  /* obsolete as of 7.3: */
  static Oid	g_last_builtin_oid; /* value of the last builtin oid */
  
! /* select and exclude tables and schemas */
! struct _relnameArg {
! 	char *name;      /* name of the table of schema */
! 	bool start;      /* wildcard at start of string */
! 	bool end;        /* wildcard at end of string */
! 	int matches;     /* how many matches did we find? */
! 	
! 	struct _relnameArg *next;
! };
! typedef struct _relnameArg relnameArg;
! 
! relnameArg *SelectTable = NULL;   /* List of tables to specifically include */
! relnameArg *ExcludeTable = NULL;  /* List of tables to specifically exclude */
! relnameArg *SelectSchema = NULL;  /* List of schemas to specifically include */
! relnameArg *ExcludeSchema = NULL; /* List of schemas to specifically exclude */
  
  char		g_opaque_type[10];	/* name for the opaque type */
  
***************
*** 205,210 ****
--- 218,226 ----
  	static int	use_setsessauth = 0;
  	static int	disable_triggers = 0;
  	char	   *outputSuperuser = NULL;
+ 	relnameArg *newname;
+ 	relnameArg *selschema = NULL, *exschema = NULL;
+ 	relnameArg *seltable = NULL, *extable = NULL;
  
  	RestoreOptions *ropt;
  
***************
*** 225,233 ****
--- 241,251 ----
  		{"no-owner", no_argument, NULL, 'O'},
  		{"port", required_argument, NULL, 'p'},
  		{"schema", required_argument, NULL, 'n'},
+ 		{"exclude-schema", required_argument, NULL, 'N'},
  		{"schema-only", no_argument, NULL, 's'},
  		{"superuser", required_argument, NULL, 'S'},
  		{"table", required_argument, NULL, 't'},
+ 		{"exclude-table", required_argument, NULL, 'T'},
  		{"password", no_argument, NULL, 'W'},
  		{"username", required_argument, NULL, 'U'},
  		{"verbose", no_argument, NULL, 'v'},
***************
*** 280,286 ****
  		}
  	}
  
! 	while ((c = getopt_long(argc, argv, "abcCdDE:f:F:h:in:oOp:RsS:t:uU:vWxX:Z:",
  							long_options, &optindex)) != -1)
  	{
  		switch (c)
--- 298,304 ----
  		}
  	}
  
! 	while ((c = getopt_long(argc, argv, "abcCdDE:f:F:h:in:N:oOp:RsS:t:T:uU:vWxX:Z:",
  							long_options, &optindex)) != -1)
  	{
  		switch (c)
***************
*** 331,338 ****
  				ignore_version = true;
  				break;
  
! 			case 'n':			/* Dump data for this schema only */
! 				selectSchemaName = strdup(optarg);
  				break;
  
  			case 'o':			/* Dump oids */
--- 349,435 ----
  				ignore_version = true;
  				break;
  
! 			case 'n': 		/* Specifically include matching schemas */
! 			case 'N':			/* Specifically exclude matching schemas */
! 			case 't':			/* Specifically include matching tables */
! 			case 'T':			/* Specifically exclude matching tables */
! 
! 				if (strlen(optarg) < 1) {
! 					fprintf(stderr,
! 							_("%s: invalid -%c option\n"),
! 							progname, c);
! 					exit(1);
! 				}
! 				/* Create a struct for this name */
! 				newname = (relnameArg *) malloc (sizeof(relnameArg));
! 				newname->start = false;
! 				newname->end = false;
! 				newname->matches = 0;
! 				newname->next = NULL;
! 
! 				/* Does it have a starting wildcard? */
! 				if (optarg[0] == '*') {
! 					/* Catch the case of "*" */
! 					if (strlen(optarg) < 2) {
! 						fprintf(stderr,
! 							_("%s: invalid wildcard option - must provide at least one character\n"),
! 							progname);
! 						free(newname);
! 						exit(1);
! 					}
! 					newname->name = strdup(optarg+1);
! 					newname->start = true;
! 				}
! 				else {
! 					newname->name = strdup(optarg);
! 				}
! 				if (newname->name[strlen(newname->name)-1] == '*') {
! 					newname->name[strlen(newname->name)-1] = '\0';
! 					newname->end = true;
! 				}
! 
! 				if (strchr(newname->name, '*') != NULL) {
! 					fprintf(stderr, 
! 						_("%s: invalid wildcard option - wildcards can only appear at start and end of names\n"),
! 						progname);
! 					free(newname);
! 					exit(1);
! 				}
! 				
! 				switch (c)
! 				{
! 					case 'n':
! 						if (selschema == NULL)
! 							SelectSchema = selschema = newname;
! 						else {
! 							selschema->next = newname;
! 							selschema = newname;
! 						}
! 						break;
! 					case 'N':
! 						if (exschema == NULL)
! 							ExcludeSchema = exschema = newname;
! 						else {
! 							exschema->next = newname;
! 							exschema = newname;
! 						}
! 						break;
! 					case 't':
! 						if (seltable == NULL)
! 							SelectTable = seltable = newname;
! 						else {
! 							seltable->next = newname;
! 							seltable = newname;
! 						}
! 						break;
! 					case 'T':
! 						if (extable == NULL)
! 							ExcludeTable = extable = newname;
! 						else {
! 							extable->next = newname;
! 							extable = newname;
! 						}
! 				}
  				break;
  
  			case 'o':			/* Dump oids */
***************
*** 360,369 ****
  				outputSuperuser = strdup(optarg);
  				break;
  
- 			case 't':			/* Dump data for this table only */
- 				selectTableName = strdup(optarg);
- 				break;
- 
  			case 'u':
  				force_password = true;
  				username = simple_prompt("User name: ", 100, true);
--- 457,462 ----
***************
*** 448,454 ****
  		exit(1);
  	}
  
! 	if (selectTableName != NULL || selectSchemaName != NULL)
  		outputBlobs = false;
  
  	if (dumpInserts == true && oids == true)
--- 541,547 ----
  		exit(1);
  	}
  
! 	if (SelectTable != NULL || SelectSchema != NULL)
  		outputBlobs = false;
  
  	if (dumpInserts == true && oids == true)
***************
*** 458,463 ****
--- 551,568 ----
  		exit(1);
  	}
  
+ 	if (SelectTable != NULL && ExcludeTable != NULL)
+ 	{
+ 		write_msg(NULL, "options \"table\" (-t) and \"exclude-table\" (-T) cannot be used together\n");
+ 		exit(1);
+ 	}
+ 
+ 	if (SelectSchema != NULL && ExcludeSchema != NULL)
+ 	{
+ 		write_msg(NULL, "options \"schema\" (-n) and \"exclude-schema\" (-N) cannot be used together\n");
+ 		exit(1);
+ 	}
+ 
  	/* open the output file */
  	switch (format[0])
  	{
***************
*** 561,567 ****
  	 * Now scan the database and create DumpableObject structs for all the
  	 * objects we intend to dump.
  	 */
! 	tblinfo = getSchemaData(&numTables, schemaOnly, dataOnly);
  
  	if (!schemaOnly)
  		getTableData(tblinfo, numTables, oids);
--- 666,672 ----
  	 * Now scan the database and create DumpableObject structs for all the
  	 * objects we intend to dump.
  	 */
! 	tblinfo = getSchemaData(&numTables);
  
  	if (!schemaOnly)
  		getTableData(tblinfo, numTables, oids);
***************
*** 600,605 ****
--- 705,711 ----
  	 */
  	getDumpableObjects(&dobjs, &numObjs);
  
+ 
  	if (g_fout->remoteVersion >= 70300)
  		sortDumpableObjectsByTypeName(dobjs, numObjs);
  	else
***************
*** 616,622 ****
  	dumpEncoding(g_fout);
  
  	/* The database item is always second, unless we don't want it at all */
! 	if (!dataOnly && selectTableName == NULL && selectSchemaName == NULL)
  		dumpDatabase(g_fout);
  
  	/* Now the rearrangeable objects. */
--- 722,728 ----
  	dumpEncoding(g_fout);
  
  	/* The database item is always second, unless we don't want it at all */
! 	if (!dataOnly && SelectTable == NULL && SelectSchema == NULL)
  		dumpDatabase(g_fout);
  
  	/* Now the rearrangeable objects. */
***************
*** 665,708 ****
  	printf(_("  %s [OPTION]... [DBNAME]\n"), progname);
  
  	printf(_("\nGeneral options:\n"));
! 	printf(_("  -f, --file=FILENAME      output file name\n"));
! 	printf(_("  -F, --format=c|t|p       output file format (custom, tar, plain text)\n"));
! 	printf(_("  -i, --ignore-version     proceed even when server version mismatches\n"
! 			 "                           pg_dump version\n"));
! 	printf(_("  -v, --verbose            verbose mode\n"));
! 	printf(_("  -Z, --compress=0-9       compression level for compressed formats\n"));
! 	printf(_("  --help                   show this help, then exit\n"));
! 	printf(_("  --version                output version information, then exit\n"));
  
  	printf(_("\nOptions controlling the output content:\n"));
! 	printf(_("  -a, --data-only          dump only the data, not the schema\n"));
! 	printf(_("  -c, --clean              clean (drop) schema prior to create\n"));
! 	printf(_("  -C, --create             include commands to create database in dump\n"));
! 	printf(_("  -d, --inserts            dump data as INSERT, rather than COPY, commands\n"));
! 	printf(_("  -D, --column-inserts     dump data as INSERT commands with column names\n"));
! 	printf(_("  -E, --encoding=ENCODING  dump the data in encoding ENCODING\n"));
! 	printf(_("  -n, --schema=SCHEMA      dump the named schema only\n"));
! 	printf(_("  -o, --oids               include OIDs in dump\n"));
! 	printf(_("  -O, --no-owner           skip restoration of object ownership\n"
! 			 "                           in plain text format\n"));
! 	printf(_("  -s, --schema-only        dump only the schema, no data\n"));
! 	printf(_("  -S, --superuser=NAME     specify the superuser user name to use in\n"
! 			 "                           plain text format\n"));
! 	printf(_("  -t, --table=TABLE        dump the named table only\n"));
! 	printf(_("  -x, --no-privileges      do not dump privileges (grant/revoke)\n"));
  	printf(_("  -X disable-dollar-quoting, --disable-dollar-quoting\n"
! 			 "                           disable dollar quoting, use SQL standard quoting\n"));
  	printf(_("  -X disable-triggers, --disable-triggers\n"
! 			 "                           disable triggers during data-only restore\n"));
  	printf(_("  -X use-set-session-authorization, --use-set-session-authorization\n"
! 			 "                           use SESSION AUTHORIZATION commands instead of\n"
! 			 "                           OWNER TO commands\n"));
  
  	printf(_("\nConnection options:\n"));
! 	printf(_("  -h, --host=HOSTNAME      database server host or socket directory\n"));
! 	printf(_("  -p, --port=PORT          database server port number\n"));
! 	printf(_("  -U, --username=NAME      connect as specified database user\n"));
! 	printf(_("  -W, --password           force password prompt (should happen automatically)\n"));
  
  	printf(_("\nIf no database name is supplied, then the PGDATABASE environment\n"
  			 "variable value is used.\n\n"));
--- 771,819 ----
  	printf(_("  %s [OPTION]... [DBNAME]\n"), progname);
  
  	printf(_("\nGeneral options:\n"));
! 	printf(_("  -f, --file=FILENAME         output file name\n"));
! 	printf(_("  -F, --format=c|t|p          output file format (custom, tar, plain text)\n"));
! 	printf(_("  -i, --ignore-version        proceed even when server version mismatches\n"
! 			 "                              pg_dump version\n"));
! 	printf(_("  -v, --verbose               verbose mode\n"));
! 	printf(_("  -Z, --compress=0-9          compression level for compressed formats\n"));
! 	printf(_("  --help                      show this help, then exit\n"));
! 	printf(_("  --version                   output version information, then exit\n"));
  
  	printf(_("\nOptions controlling the output content:\n"));
! 	printf(_("  -a, --data-only             dump only the data, not the schema\n"));
! 	printf(_("  -c, --clean                 clean (drop) schema prior to create\n"));
! 	printf(_("  -C, --create                include commands to create database in dump\n"));
! 	printf(_("  -d, --inserts               dump data as INSERT, rather than COPY, commands\n"));
! 	printf(_("  -D, --column-inserts        dump data as INSERT commands with column names\n"));
! 	printf(_("  -E, --encoding=ENCODING     dump the data in encoding ENCODING\n"));
! 	printf(_("  -n, --schema=SCHEMA         dump the named schema only\n"));
! 	printf(_("  -N, --exclude-schema=SCHEMA do NOT dump the named schema\n"));
! 	printf(_("  -t, --table=TABLE           dump the named table only\n"));
! 	printf(_("  -T, --exclude-table=TABLE   do NOT dump the named table\n"));
! 	printf(_("     NOTE: The -n, -N, -t, and -T options can be called multiple times. Limited\n"
! 					 "     wildcard support is available by placing a star (*) at the start and/or end\n"
! 					 "     of the name: -N \"foo*\"   -t \"*bar\"   -t \"*baz*\"\n"));
! 	printf(_("  -o, --oids                  include OIDs in dump\n"));
! 	printf(_("  -O, --no-owner              skip restoration of object ownership\n"
! 			 "                              in plain text format\n"));
! 	printf(_("  -s, --schema-only           dump only the schema, no data\n"));
! 	printf(_("  -S, --superuser=NAME        specify the superuser user name to use in\n"
! 			 "                              plain text format\n"));
! 	printf(_("  -x, --no-privileges         do not dump privileges (grant/revoke)\n"));
  	printf(_("  -X disable-dollar-quoting, --disable-dollar-quoting\n"
! 			 "                              disable dollar quoting, use SQL standard quoting\n"));
  	printf(_("  -X disable-triggers, --disable-triggers\n"
! 			 "                              disable triggers during data-only restore\n"));
  	printf(_("  -X use-set-session-authorization, --use-set-session-authorization\n"
! 			 "                              use SESSION AUTHORIZATION commands instead of\n"
! 			 "                              OWNER TO commands\n"));
  
  	printf(_("\nConnection options:\n"));
! 	printf(_("  -h, --host=HOSTNAME         database server host or socket directory\n"));
! 	printf(_("  -p, --port=PORT             database server port number\n"));
! 	printf(_("  -U, --username=NAME         connect as specified database user\n"));
! 	printf(_("  -W, --password              force password prompt (should happen automatically)\n"));
  
  	printf(_("\nIf no database name is supplied, then the PGDATABASE environment\n"
  			 "variable value is used.\n\n"));
***************
*** 712,717 ****
--- 823,846 ----
  void
  exit_nicely(void)
  {
+ 	/* Free up all the relnameArg structs */
+ 	int i;
+ 	relnameArg *currname, *nextname;
+ 
+ 	for (i=1; i<=4; i++) {
+ 		currname = i==1 ?
+ 			SelectSchema : i==2 ? 
+ 			ExcludeSchema : i==3 ? 
+ 			SelectTable : 
+ 			ExcludeTable;
+ 		while (currname != NULL) {
+ 			nextname = currname -> next;
+ 			free(currname->name);
+ 			free(currname);
+ 			currname = nextname;
+ 		}
+ 	}
+ 
  	PQfinish(g_conn);
  	if (g_verbose)
  		write_msg(NULL, "*** aborted because of error\n");
***************
*** 719,749 ****
  }
  
  /*
   * selectDumpableNamespace: policy-setting subroutine
   *		Mark a namespace as to be dumped or not
   */
  static void
  selectDumpableNamespace(NamespaceInfo *nsinfo)
  {
  	/*
! 	 * If a specific table is being dumped, do not dump any complete
! 	 * namespaces.	If a specific namespace is being dumped, dump just that
! 	 * namespace. Otherwise, dump all non-system namespaces.
! 	 */
! 	if (selectTableName != NULL)
! 		nsinfo->dump = false;
! 	else if (selectSchemaName != NULL)
! 	{
! 		if (strcmp(nsinfo->dobj.name, selectSchemaName) == 0)
  			nsinfo->dump = true;
! 		else
! 			nsinfo->dump = false;
  	}
! 	else if (strncmp(nsinfo->dobj.name, "pg_", 3) == 0 ||
! 			 strcmp(nsinfo->dobj.name, "information_schema") == 0)
! 		nsinfo->dump = false;
! 	else
! 		nsinfo->dump = true;
  }
  
  /*
--- 848,961 ----
  }
  
  /*
+  * checkNameMatch: See if a name matches a relnameArg list
+  * If third arg is false, decrement matches
+  */
+ static bool
+ checkNameMatch(relnameArg *namelist, const char *name, bool updown)
+ {
+ 
+ 	int i,j, k;
+ 	relnameArg *thisrel;
+ 
+ 	/* Used to reset matches on false hits */
+ 	k = updown ? 1 : -1;
+ 
+ 	if (namelist == NULL)
+ 		return false;
+ 
+ 	for (thisrel = namelist; thisrel != NULL; thisrel = thisrel->next) {
+ 		/*
+ 		 * Wildcard on both sides: "*foo*"
+ 		 */
+ 		if (thisrel->start && thisrel->end) { /* "*foo*" */
+ 			if (strstr(name, thisrel->name) != NULL) {
+ 				thisrel->matches += k;
+ 				return true;
+ 			}
+ 		}
+ 		/*
+ 		 * Wildcard at end: "foo*"
+ 		 */
+ 		else if (thisrel->end) {
+ 			if (strncmp(name, thisrel->name, strlen(thisrel->name)) == 0) {
+ 				thisrel->matches += k;
+ 				return true;
+ 			}
+ 		}
+ 		/*
+ 		 * Wildcard at start: "*foo"
+ 		 */
+ 		else if (thisrel->start) {
+ 			if (strlen(name) >= strlen(thisrel->name)) {
+ 				for (i=strlen(name)-1, j = strlen(thisrel->name)-1; j>=0; i--, j--) {
+ 					if (name[i] != thisrel->name[j])
+ 						break;
+ 				}
+ 				if (j<0) {
+ 					thisrel->matches += k;
+ 					return true;
+ 				}
+ 			}
+ 		}
+ 		/*
+ 		 * Straight comparison: "foo"
+ 		 */
+ 		else if (strcmp(name, thisrel->name) == 0) {
+ 			thisrel->matches += k;
+ 			return true;
+ 		}
+ 	} /* end each list item */
+ 
+ 	return false;
+ }
+ 
+ 
+ /*
   * selectDumpableNamespace: policy-setting subroutine
   *		Mark a namespace as to be dumped or not
   */
  static void
  selectDumpableNamespace(NamespaceInfo *nsinfo)
  {
+ 
+ 	nsinfo->dump = false;
+ 
+ 	/* Always dump if -t was used: trumps the -N flag */
  	/*
! 	if (SelectTable != NULL) {
! 		nsinfo->dump = true;
! 		return;
! 	}
! 	*/
! 	/* 
! 	 * If -n was used, dump if match, do not dump if no match
! 	 */
! 	if (SelectSchema != NULL) {
! 		if (checkNameMatch(SelectSchema, nsinfo->dobj.name, true))
  			nsinfo->dump = true;
! 		return;
  	}
! 	/*
! 	 * Do not dump if -N was used and we match
! 	 */
! 	else if (checkNameMatch(ExcludeSchema, nsinfo->dobj.name, true)) {
! 		return;
! 	}
! 	/*
! 	 * Do not dump if a system namespace
! 	 */
! 	if (strncmp(nsinfo->dobj.name, "pg_", 3) == 0 ||
!  		  strcmp(nsinfo->dobj.name, "information_schema") == 0) {
! 		return;
! 	}
! 	/*
! 	 * Do not dump if -t was used, else dump
! 	 */
! 	if (SelectTable != NULL) {
! 		return;
! 	}
! 	nsinfo->dump = true;
  }
  
  /*
***************
*** 753,775 ****
  static void
  selectDumpableTable(TableInfo *tbinfo)
  {
  	/*
! 	 * Always dump if dumping parent namespace; else, if a particular
! 	 * tablename has been specified, dump matching table name; else, do not
! 	 * dump.
  	 */
! 	tbinfo->dump = false;
! 	if (tbinfo->dobj.namespace->dump)
  		tbinfo->dump = true;
! 	else if (selectTableName != NULL &&
! 			 strcmp(tbinfo->dobj.name, selectTableName) == 0)
! 	{
! 		/* If both -s and -t specified, must match both to dump */
! 		if (selectSchemaName == NULL)
! 			tbinfo->dump = true;
! 		else if (strcmp(tbinfo->dobj.namespace->dobj.name, selectSchemaName) == 0)
! 			tbinfo->dump = true;
  	}
  }
  
  /*
--- 965,1007 ----
  static void
  selectDumpableTable(TableInfo *tbinfo)
  {
+ 
  	/*
! 	 * Do not dump if using -T and we match
! 	 * unless we are using -n and we match (-n trumps -T)
! 	 */
! 	if (checkNameMatch(ExcludeTable, tbinfo->dobj.name, true)) {
! 		if (SelectSchema == NULL ||
! 				checkNameMatch(SelectSchema, tbinfo->dobj.namespace->dobj.name, true))
! 			return;
! 		/* Matched table but not schema, so go back and decrement matches */
! 		checkNameMatch(ExcludeTable, tbinfo->dobj.name, false);
! 	}
! 
! 	/* 
! 	 * If using -t, dump if we match via -t and -n (if used)
! 	 * Otherwise, do not dump
  	 */
! 
! 	if (SelectTable != NULL) {
! 		if (checkNameMatch(SelectTable, tbinfo->dobj.name, true)) {
! 			if (SelectSchema == NULL ||
! 					checkNameMatch(SelectSchema, tbinfo->dobj.namespace->dobj.name, true)) {
! 				tbinfo->dump = true;
! 				return;
! 			}
! 			/* Matched table but not schema, so go back and decrement matches */
! 			checkNameMatch(SelectTable, tbinfo->dobj.name, false);
! 		}
! 		return;
! 	}
! 
! 	/* Dump if this namespace is being dumped */
! 	if (tbinfo->dobj.namespace->dump) {
  		tbinfo->dump = true;
! 		return;
  	}
+ 
  }
  
  /*
***************
*** 1546,1551 ****
--- 1778,1784 ----
  	int			i;
  	PQExpBuffer query;
  	NamespaceInfo *nsinfo;
+ 	relnameArg *thisrel;
  	int			i_tableoid;
  	int			i_oid;
  	int			i_nspname;
***************
*** 1632,1652 ****
  	}
  
  	/*
! 	 * If the user attempted to dump a specific namespace, check to ensure
! 	 * that the specified namespace actually exists.
  	 */
! 	if (selectSchemaName)
! 	{
! 		for (i = 0; i < ntups; i++)
! 			if (strcmp(nsinfo[i].dobj.name, selectSchemaName) == 0)
! 				break;
! 
! 		/* Didn't find a match */
! 		if (i == ntups)
! 		{
! 			write_msg(NULL, "specified schema \"%s\" does not exist\n",
! 					  selectSchemaName);
! 			exit_nicely();
  		}
  	}
  
--- 1865,1882 ----
  	}
  
  	/*
! 	 * Bail out if the user attempted to dump a non-existent namespace 
! 	 * with the -n option. Let -N silently "fail"
  	 */
! 	if (SelectSchema != NULL) {
! 		for (thisrel = SelectSchema; thisrel != NULL; thisrel = thisrel->next) {
! 			if (thisrel->matches == 0) {
! 				write_msg(NULL, "no matching schema was found for \"%s%s%s\"\n",
! 									thisrel->start ? "*" : "",
! 									thisrel->name,
! 									thisrel->end ? "*" : "");
! 				exit_nicely();
! 			}
  		}
  	}
  
***************
*** 2414,2419 ****
--- 2644,2650 ----
  	PQExpBuffer delqry = createPQExpBuffer();
  	PQExpBuffer lockquery = createPQExpBuffer();
  	TableInfo  *tblinfo;
+ 	relnameArg *thisrel;
  	int			i_reltableoid;
  	int			i_reloid;
  	int			i_relname;
***************
*** 2682,2703 ****
  	}
  
  	/*
! 	 * If the user is attempting to dump a specific table, check to ensure
! 	 * that the specified table actually exists.  (This is a bit simplistic
! 	 * since we don't fully check the combination of -n and -t switches.)
  	 */
! 	if (selectTableName)
! 	{
! 		for (i = 0; i < ntups; i++)
! 			if (strcmp(tblinfo[i].dobj.name, selectTableName) == 0)
! 				break;
! 
! 		/* Didn't find a match */
! 		if (i == ntups)
! 		{
! 			write_msg(NULL, "specified table \"%s\" does not exist\n",
! 					  selectTableName);
! 			exit_nicely();
  		}
  	}
  
--- 2913,2930 ----
  	}
  
  	/*
! 	 * Bail out if the user attempted to drop a non-existent table with 
! 	 * the -t option. Let -T silently "fail"
  	 */
! 	if (SelectTable != NULL) {
! 		for (thisrel = SelectTable; thisrel != NULL; thisrel = thisrel->next) {
! 			if (thisrel->matches == 0) {
! 				write_msg(NULL, "no matching table was found for \"%s%s%s\"\n",
! 									thisrel->start ? "*" : "",
! 									thisrel->name,
! 									thisrel->end ? "*" : "");
! 				exit_nicely();
! 			}
  		}
  	}
  
***************
*** 5101,5107 ****
  static bool
  shouldDumpProcLangs(void)
  {
! 	if (selectTableName != NULL || selectSchemaName != NULL)
  		return false;
  	/* And they're schema not data */
  	if (dataOnly)
--- 5328,5334 ----
  static bool
  shouldDumpProcLangs(void)
  {
! 	if (SelectTable != NULL || SelectSchema != NULL)
  		return false;
  	/* And they're schema not data */
  	if (dataOnly)
Index: src/bin/pg_dump/pg_dump.h
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_dump.h,v
retrieving revision 1.123
diff -c -r1.123 pg_dump.h
*** src/bin/pg_dump/pg_dump.h	3 Dec 2005 21:06:18 -0000	1.123
--- src/bin/pg_dump/pg_dump.h	16 Jan 2006 01:53:38 -0000
***************
*** 331,339 ****
   *	common utility functions
   */
  
! extern TableInfo *getSchemaData(int *numTablesPtr,
! 			  const bool schemaOnly,
! 			  const bool dataOnly);
  
  typedef enum _OidOptions
  {
--- 331,337 ----
   *	common utility functions
   */
  
! extern TableInfo *getSchemaData(int *numTablesPtr);
  
  typedef enum _OidOptions
  {
---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to