*** ./src/bin/pg_dump/pg_dump.c.orig	Mon Feb 18 20:17:59 2002
--- ./src/bin/pg_dump/pg_dump.c	Mon Feb 18 21:16:37 2002
***************
*** 4251,4257 ****
  
  
  
! 				/* put the CONSTRAINTS inside the table def */
  				for (k = 0; k < tblinfo[i].ncheck; k++)
  				{
  					if (actual_atts + k > 0)
--- 4251,4257 ----
  
  
  
! 				/* Put the CONSTRAINTS inside the table def */
  				for (k = 0; k < tblinfo[i].ncheck; k++)
  				{
  					if (actual_atts + k > 0)
***************
*** 4261,4268 ****
  									  tblinfo[i].check_expr[k]);
  				}
  
! 				/* Primary Key */
! 				if (tblinfo[i].pkIndexOid != NULL)
  				{
  					PQExpBuffer consDef;
  
--- 4261,4276 ----
  									  tblinfo[i].check_expr[k]);
  				}
  
! 				/*
! 				 * Primary Key: In versions of PostgreSQL prior to 7.2, we
! 				 * need to include the primary key in the table definition,
! 				 * using the following code. However, this is not ideal
! 				 * because it creates an index on the table, which slows
! 				 * down COPYing data into the table. As of release 7.2, we
! 				 * can add primary keys to a table after it has been
! 				 * defined using ALTER TABLE. This is done in dumpIndexes().
! 				 */
! 				if (g_fout->remoteVersion < 70200 && (tblinfo[i].pkIndexOid != NULL))
  				{
  					PQExpBuffer consDef;
  
***************
*** 4446,4472 ****
  		/* Handle PK indexes */
  		if (strcmp(indinfo[i].indisprimary, "t") == 0)
  		{
- #if 0
- 
  			/*
! 			 * PK: Enable this code when ALTER TABLE supports PK
! 			 * constraints.
  			 */
  
! 			PQExpBuffer consDef = getPKconstraint(&tblinfo[tableInd], &indinfo[i]);
! 
! 			resetPQExpBuffer(q);
  
! 			appendPQExpBuffer(q, "Alter Table %s Add %s;",
! 						  fmtId(tblinfo[tableInd].relname, force_quotes),
! 							  consDef->data);
! 
! 			ArchiveEntry(fout, indinfo[i].oid, tblinfo[tableInd].primary_key_name,
! 						 "CONSTRAINT", NULL, q->data, "",
! 						 "", tblinfo[tableInd].usename, NULL, NULL);
  
! 			destroyPQExpBuffer(consDef);
! #endif
  
  			/*
  			 * Don't need to do anything else for this system-generated
--- 4454,4480 ----
  		/* Handle PK indexes */
  		if (strcmp(indinfo[i].indisprimary, "t") == 0)
  		{
  			/*
! 			 * As of release 7.2, ALTER TABLE supports adding PKs to a table after
! 			 * it has been created. This is the preferred method of defining
! 			 * primary keys.
  			 */
+ 			if (g_fout->remoteVersion >= 70200)
+ 			{
+ 				PQExpBuffer consDef = getPKconstraint(&tblinfo[tableInd], &indinfo[i]);
  
! 				resetPQExpBuffer(q);
  
! 				appendPQExpBuffer(q, "Alter Table %s Add %s;",
! 							  fmtId(tblinfo[tableInd].relname, force_quotes),
! 								  consDef->data);
! 
! 				ArchiveEntry(fout, indinfo[i].indexreloid, tblinfo[tableInd].primary_key_name,
! 							 "CONSTRAINT", NULL, q->data, "",
! 							 "", tblinfo[tableInd].usename, NULL, NULL);
  
! 				destroyPQExpBuffer(consDef);
! 			}
  
  			/*
  			 * Don't need to do anything else for this system-generated
