Index: src/bin/pg_dump/pg_dump.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v
retrieving revision 1.271
diff -c -r1.271 pg_dump.c
*** src/bin/pg_dump/pg_dump.c	2002/07/12 18:43:18	1.271
--- src/bin/pg_dump/pg_dump.c	2002/07/13 13:43:09
***************
*** 4845,4851 ****
  	int			i_indexreloid;
  	int			i_indexrelname;
  	int			i_indexdef;
! 	int			i_indisprimary;
  	int			i_indkey;
  	int			i_indnkeys;
  
--- 4845,4851 ----
  	int			i_indexreloid;
  	int			i_indexrelname;
  	int			i_indexdef;
! 	int			i_contype;
  	int			i_indkey;
  	int			i_indnkeys;
  
***************
*** 4867,4880 ****
  		if (g_fout->remoteVersion >= 70300)
  			appendPQExpBuffer(query,
  							  "SELECT i.indexrelid as indexreloid, "
! 							  "t.relname as indexrelname, "
  							  "pg_catalog.pg_get_indexdef(i.indexrelid) as indexdef, "
! 							  "i.indisprimary, i.indkey, "
! 							  "t.relnatts as indnkeys "
! 							  "FROM pg_catalog.pg_index i, "
! 							  "pg_catalog.pg_class t "
! 							  "WHERE t.oid = i.indexrelid "
! 							  "AND i.indrelid = '%s'::pg_catalog.oid "
  							  "ORDER BY indexrelname",
  							  tbinfo->oid);
  		else
--- 4867,4882 ----
  		if (g_fout->remoteVersion >= 70300)
  			appendPQExpBuffer(query,
  							  "SELECT i.indexrelid as indexreloid, "
! 							  "coalesce(c.conname, t.relname) as indexrelname, "
  							  "pg_catalog.pg_get_indexdef(i.indexrelid) as indexdef, "
! 							  "i.indkey, "
! 							  "t.relnatts as indnkeys, "
! 							  "coalesce(c.contype, '0') as contype " 
! 							  "FROM pg_catalog.pg_index i "
! 							  "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
! 							  "LEFT OUTER JOIN pg_catalog.pg_constraint c "
! 							  "  ON (c.conrelid = i.indrelid AND c.conname = t.relname) "
! 							  "WHERE i.indrelid = '%s'::pg_catalog.oid "
  							  "ORDER BY indexrelname",
  							  tbinfo->oid);
  		else
***************
*** 4882,4889 ****
  							  "SELECT i.indexrelid as indexreloid, "
  							  "t.relname as indexrelname, "
  							  "pg_get_indexdef(i.indexrelid) as indexdef, "
! 							  "i.indisprimary, i.indkey, "
! 							  "t.relnatts as indnkeys "
  							  "FROM pg_index i, pg_class t "
  							  "WHERE t.oid = i.indexrelid "
  							  "AND i.indrelid = '%s'::oid "
--- 4884,4894 ----
  							  "SELECT i.indexrelid as indexreloid, "
  							  "t.relname as indexrelname, "
  							  "pg_get_indexdef(i.indexrelid) as indexdef, "
! 							  "i.indkey, "
! 							  "t.relnatts as indnkeys, "
! 							  "CASE WHEN i.indisprimary IS TRUE THEN "
! 							  "  'p'::char "
! 							  "ELSE '0'::char END as contype "
  							  "FROM pg_index i, pg_class t "
  							  "WHERE t.oid = i.indexrelid "
  							  "AND i.indrelid = '%s'::oid "
***************
*** 4903,4909 ****
  		i_indexreloid = PQfnumber(res, "indexreloid");
  		i_indexrelname = PQfnumber(res, "indexrelname");
  		i_indexdef = PQfnumber(res, "indexdef");
! 		i_indisprimary = PQfnumber(res, "indisprimary");
  		i_indkey = PQfnumber(res, "indkey");
  		i_indnkeys = PQfnumber(res, "indnkeys");
  
--- 4908,4914 ----
  		i_indexreloid = PQfnumber(res, "indexreloid");
  		i_indexrelname = PQfnumber(res, "indexrelname");
  		i_indexdef = PQfnumber(res, "indexdef");
! 		i_contype = PQfnumber(res, "contype");
  		i_indkey = PQfnumber(res, "indkey");
  		i_indnkeys = PQfnumber(res, "indnkeys");
  
***************
*** 4912,4925 ****
  			const char *indexreloid = PQgetvalue(res, j, i_indexreloid);
  			const char *indexrelname = PQgetvalue(res, j, i_indexrelname);
  			const char *indexdef = PQgetvalue(res, j, i_indexdef);
! 			const char *indisprimary = PQgetvalue(res, j, i_indisprimary);
  
  			resetPQExpBuffer(q);
  			resetPQExpBuffer(delq);
  
! 			if (strcmp(indisprimary, "t") == 0)
  			{
! 				/* Handle PK indexes specially */
  				int indnkeys = atoi(PQgetvalue(res, j, i_indnkeys));
  				char **indkeys = (char **) malloc(indnkeys * sizeof(char *));
  				int			k;
--- 4917,4934 ----
  			const char *indexreloid = PQgetvalue(res, j, i_indexreloid);
  			const char *indexrelname = PQgetvalue(res, j, i_indexrelname);
  			const char *indexdef = PQgetvalue(res, j, i_indexdef);
! 			const char *contype = PQgetvalue(res, j, i_contype);
  
  			resetPQExpBuffer(q);
  			resetPQExpBuffer(delq);
  
! 			if (strcmp(contype, "p") == 0 || strcmp(contype, "u") == 0)
  			{
! 				/*
! 				 * Constraints which are marked as so (created with a
! 				 * constraint creation utility statement, not an index
! 				 * creation statment) should be regenerated as such.
! 				 */
  				int indnkeys = atoi(PQgetvalue(res, j, i_indnkeys));
  				char **indkeys = (char **) malloc(indnkeys * sizeof(char *));
  				int			k;
***************
*** 4929,4936 ****
  
  				appendPQExpBuffer(q, "ALTER TABLE %s ADD ",
  								  fmtId(tbinfo->relname, force_quotes));
! 				appendPQExpBuffer(q, "CONSTRAINT %s PRIMARY KEY (",
! 								  fmtId(indexrelname, force_quotes));
  
  				for (k = 0; k < indnkeys; k++)
  				{
--- 4938,4946 ----
  
  				appendPQExpBuffer(q, "ALTER TABLE %s ADD ",
  								  fmtId(tbinfo->relname, force_quotes));
! 				appendPQExpBuffer(q, "CONSTRAINT %s %s (",
! 								  fmtId(indexrelname, force_quotes),
! 								  strcmp(contype, "p") == 0 ? "PRIMARY KEY" : "UNIQUE");
  
  				for (k = 0; k < indnkeys; k++)
  				{
