Index: doc/src/sgml/ref/pg_dump.sgml
===================================================================
RCS file: /var/lib/cvs/pgsql-server/doc/src/sgml/ref/pg_dump.sgml,v
retrieving revision 1.54
diff -c -r1.54 pg_dump.sgml
*** doc/src/sgml/ref/pg_dump.sgml	6 Jan 2003 18:53:24 -0000	1.54
--- doc/src/sgml/ref/pg_dump.sgml	10 Jan 2003 17:49:03 -0000
***************
*** 284,289 ****
--- 284,312 ----
       </varlistentry>
  
       <varlistentry>
+       <term><option>-n <replaceable class="parameter">namespace</replaceable></option></term>
+       <term><option>--namespace=<replaceable class="parameter">namespace</replaceable></option></term>
+       <listitem>
+        <para>
+         Dump the contents of <replaceable
+         class="parameter">namespace</replaceable> only. If this option
+         is not specified, all non-system namespaces in the target
+         database will be dumped.
+        </para>
+ 
+        <note>
+         <para>
+          In this mode, <application>pg_dump</application> makes no
+          attempt to dump any other database objects that may depend
+          upon objects in the selected namespace. Therefore, there is
+          no guarantee that the results of a single namespace dump can
+          be successfully restored by themselves into a clean database.
+         </para>
+        </note>
+       </listitem>
+      </varlistentry>
+ 
+      <varlistentry>
        <term><option>-o</></term>
        <term><option>--oids</></term>
        <listitem>
***************
*** 380,387 ****
        <term><option>--table=<replaceable class="parameter">table</replaceable></option></term>
        <listitem>
         <para>
! 	Dump data for <replaceable class="parameter">table</replaceable> only.
         </para>
        </listitem>
       </varlistentry>
  
--- 403,422 ----
        <term><option>--table=<replaceable class="parameter">table</replaceable></option></term>
        <listitem>
         <para>
! 	Dump data for <replaceable class="parameter">table</replaceable>
! 	only. If <literal>*</literal> is specified, all tables in the
! 	specified database will be dumped.
         </para>
+ 
+        <note>
+         <para>
+          In this mode, <application>pg_dump</application> makes no
+          attempt to dump any other database objects that may depend
+          upon the selected table. Therefore, there is no guarantee
+          that the results of a single table dump can be successfully
+          restored by themselves into a clean database.
+         </para>
+        </note>
        </listitem>
       </varlistentry>
  
***************
*** 495,504 ****
        <term><option>--host=<replaceable class="parameter">host</replaceable></option></term>
        <listitem>
         <para>
! 	Specifies the host name of the machine on which the 
! 	server
! 	is running.  If host begins with a slash, it is used 
! 	as the directory for the Unix domain socket.
         </para>
        </listitem>
       </varlistentry>
--- 530,538 ----
        <term><option>--host=<replaceable class="parameter">host</replaceable></option></term>
        <listitem>
         <para>
! 	Specifies the host name of the machine on which the server is
! 	running.  If the host name begins with a slash, it is used as the
! 	directory for the Unix domain socket.
         </para>
        </listitem>
       </varlistentry>
***************
*** 551,557 ****
  
      <listitem>
       <para>
!       Default connection parameters
       </para>
      </listitem>
     </varlistentry>
--- 585,591 ----
  
      <listitem>
       <para>
!       Default connection parameters.
       </para>
      </listitem>
     </varlistentry>
***************
*** 578,588 ****
  
      <msgexplan>
         <para>
! 	<application>pg_dump</application> could not attach to the 
! 	PostgreSQL server on the specified host and port.  If you see this message,
! 	ensure that the server
! 	is running on the proper host and that you have specified the proper
! 	port.
         </para>
      </msgexplan>
     </msgentry>
--- 612,621 ----
  
      <msgexplan>
         <para>
! 	<application>pg_dump</application> could not connect to the
! 	PostgreSQL server on the specified host and port.  If you see this
! 	message, ensure that the server is running on the proper host and
! 	that you have specified the proper port.
         </para>
      </msgexplan>
     </msgentry>
***************
*** 630,636 ****
  
      <listitem>
       <para>
!       When doing a data only dump, <application>pg_dump</application> emits queries
        to disable triggers on user tables before inserting the data and queries to
        re-enable them after the data has been inserted.  If the restore is stopped
        in the middle, the system catalogs may be left in the wrong state.
--- 663,669 ----
  
      <listitem>
       <para>
!       When doing a data-only dump, <application>pg_dump</application> emits queries
        to disable triggers on user tables before inserting the data and queries to
        re-enable them after the data has been inserted.  If the restore is stopped
        in the middle, the system catalogs may be left in the wrong state.
Index: src/bin/pg_dump/pg_dump.c
===================================================================
RCS file: /var/lib/cvs/pgsql-server/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.314
diff -c -r1.314 pg_dump.c
*** src/bin/pg_dump/pg_dump.c	6 Jan 2003 18:53:24 -0000	1.314
--- src/bin/pg_dump/pg_dump.c	10 Jan 2003 17:46:19 -0000
***************
*** 70,75 ****
--- 70,76 ----
  } DumpContext;
  
  static void help(const char *progname);
+ static void formatIdentifierArg(char *identifier);
  static NamespaceInfo *findNamespace(const char *nsoid, const char *objoid);
  static void dumpClasses(const TableInfo *tblinfo, const int numTables,
  			Archive *fout, const bool oids);
***************
*** 142,148 ****
  /* 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 */
  
  char		g_opaque_type[10];	/* name for the opaque type */
  
--- 143,150 ----
  /* 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 */
  
***************
*** 196,201 ****
--- 198,204 ----
  		{"column-inserts", no_argument, NULL, 'D'},
  		{"host", required_argument, NULL, 'h'},
  		{"ignore-version", no_argument, NULL, 'i'},
+ 		{"namespace", required_argument, NULL, 'n'},
  		{"no-reconnect", no_argument, NULL, 'R'},
  		{"oids", no_argument, NULL, 'o'},
  		{"no-owner", no_argument, NULL, 'O'},
***************
*** 263,269 ****
  		}
  	}
  
! 	while ((c = getopt_long(argc, argv, "abcCdDf:F:h:ioOp:RsS:t:uU:vWxX:Z:",
  							long_options, &optindex)) != -1)
  	{
  		switch (c)
--- 266,272 ----
  		}
  	}
  
! 	while ((c = getopt_long(argc, argv, "abcCdDf:F:h:in:oOp:RsS:t:uU:vWxX:Z:",
  							long_options, &optindex)) != -1)
  	{
  		switch (c)
***************
*** 311,316 ****
--- 314,324 ----
  				ignore_version = true;
  				break;
  
+ 			case 'n':			/* Dump data for this schema only */
+ 				selectSchemaName = strdup(optarg);
+ 				formatIdentifierArg(selectSchemaName);
+ 				break;
+ 
  			case 'o':			/* Dump oids */
  				oids = true;
  				break;
***************
*** 337,375 ****
  				break;
  
  			case 't':			/* Dump data for this table only */
! 				{
! 					int			i;
  
! 					selectTablename = strdup(optarg);
  
- 					/*
- 					 * quoted string? Then strip quotes and preserve
- 					 * case...
- 					 */
- 					if (selectTablename[0] == '"')
- 					{
- 						char	   *endptr;
- 
- 						endptr = selectTablename + strlen(selectTablename) - 1;
- 						if (*endptr == '"')
- 							*endptr = '\0';
- 						strcpy(selectTablename, &selectTablename[1]);
- 					}
- 					else
- 					{
- 						/* otherwise, convert table name to lowercase... */
- 						for (i = 0; selectTablename[i]; i++)
- 							if (isupper((unsigned char) selectTablename[i]))
- 								selectTablename[i] = tolower((unsigned char) selectTablename[i]);
- 
- 						/*
- 						 * '*' is a special case meaning ALL tables, but
- 						 * only if unquoted
- 						 */
- 						if (strcmp(selectTablename, "*") == 0)
- 							selectTablename[0] = '\0';
- 					}
- 				}
  				break;
  
  			case 'u':
--- 345,362 ----
  				break;
  
  			case 't':			/* Dump data for this table only */
! 				selectTableName = strdup(optarg);
  
! 				/*
! 				 * '*' is a special case meaning ALL tables, but
! 				 * only if unquoted
! 				 */
! 				if (selectTableName[0] != '"' &&
! 					strcmp(selectTableName, "*") == 0)
! 					selectTableName[0] = '\0';
! 				else
! 					formatIdentifierArg(selectTableName);
  
  				break;
  
  			case 'u':
***************
*** 454,466 ****
  		exit(1);
  	}
  
! 	if (outputBlobs && selectTablename != NULL && strlen(selectTablename) > 0)
  	{
  		write_msg(NULL, "Large object output is not supported for a single table.\n");
  		write_msg(NULL, "Use all tables or a full dump instead.\n");
  		exit(1);
  	}
  
  	if (dumpData == true && oids == true)
  	{
  		write_msg(NULL, "INSERT (-d, -D) and OID (-o) options cannot be used together.\n");
--- 441,467 ----
  		exit(1);
  	}
  
! 	if (outputBlobs && selectTableName != NULL && strlen(selectTableName) > 0)
  	{
  		write_msg(NULL, "Large object output is not supported for a single table.\n");
  		write_msg(NULL, "Use all tables or a full dump instead.\n");
  		exit(1);
  	}
  
+ 	if (outputBlobs && selectSchemaName != NULL)
+ 	{
+ 		write_msg(NULL, "Large object output is not supported for a single namespace.");
+ 		write_msg(NULL, "Use a full dump instead.\n");
+ 		exit(1);
+ 	}
+ 
+ 	if (selectTableName != NULL && selectSchemaName != NULL)
+ 	{
+ 		write_msg(NULL, "Single table and single schema dumps cannot be used simultaneously.\n");
+ 		write_msg(NULL, "Use one option or the other, not both.\n");
+ 		exit(1);
+ 	}
+ 
  	if (dumpData == true && oids == true)
  	{
  		write_msg(NULL, "INSERT (-d, -D) and OID (-o) options cannot be used together.\n");
***************
*** 665,670 ****
--- 666,672 ----
  	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(_("  -n, --namespace=NAME     dump this namespace only\n"));
  	printf(_("  -o, --oids               include OIDs in dump\n"));
  	printf(_("  -O, --no-owner           do not output \\connect commands in plain\n"
  			 "                           text format\n"));
***************
*** 692,697 ****
--- 694,730 ----
  	printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
  }
  
+ /*
+  * Accepts an identifier as specified as a command-line argument, and
+  * converts it into a form acceptable to the PostgreSQL backend.
+  */
+ static void
+ formatIdentifierArg(char *identifier)
+ {
+ 	/*
+ 	 * quoted string? Then strip quotes and preserve
+ 	 * case...
+ 	 */
+ 	if (identifier[0] == '"')
+ 	{
+ 		char	   *endptr;
+ 
+ 		endptr = identifier + strlen(identifier) - 1;
+ 		if (*endptr == '"')
+ 			*endptr = '\0';
+ 		strcpy(identifier, &identifier[1]);
+ 	}
+ 	else
+ 	{
+ 		int i;
+ 
+ 		/* otherwise, convert identifier name to lowercase... */
+ 		for (i = 0; identifier[i]; i++)
+ 			if (isupper((unsigned char) identifier[i]))
+ 				identifier[i] = tolower((unsigned char) identifier[i]);
+ 	}
+ }
+ 
  void
  exit_nicely(void)
  {
***************
*** 710,719 ****
  {
  	/*
  	 * If a specific table is being dumped, do not dump any complete
! 	 * namespaces.	Otherwise, dump all non-system namespaces.
  	 */
! 	if (selectTablename != NULL)
  		nsinfo->dump = false;
  	else if (strncmp(nsinfo->nspname, "pg_", 3) == 0 ||
  			 strcmp(nsinfo->nspname, "information_schema") == 0)
  		nsinfo->dump = false;
--- 743,760 ----
  {
  	/*
  	 * 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->nspname, selectSchemaName) == 0)
+ 			nsinfo->dump = true;
+ 		else
+ 			nsinfo->dump = false;
+ 	}
  	else if (strncmp(nsinfo->nspname, "pg_", 3) == 0 ||
  			 strcmp(nsinfo->nspname, "information_schema") == 0)
  		nsinfo->dump = false;
***************
*** 735,742 ****
  	 */
  	if (tbinfo->relnamespace->dump)
  		tbinfo->dump = true;
! 	else if (selectTablename != NULL)
! 		tbinfo->dump = (strcmp(tbinfo->relname, selectTablename) == 0);
  	else
  		tbinfo->dump = false;
  }
--- 776,783 ----
  	 */
  	if (tbinfo->relnamespace->dump)
  		tbinfo->dump = true;
! 	else if (selectTableName != NULL)
! 		tbinfo->dump = (strcmp(tbinfo->relname, selectTableName) == 0);
  	else
  		tbinfo->dump = false;
  }
