1212 * by PostgreSQL
1313 *
1414 * IDENTIFICATION
15- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.346 2003/08/28 20:21:34 tgl Exp $
15+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.347 2003/09/19 23:15:18 tgl Exp $
1616 *
1717 *-------------------------------------------------------------------------
1818 */
@@ -5506,6 +5506,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
55065506 int i_indexrelname ;
55075507 int i_indexdef ;
55085508 int i_contype ;
5509+ int i_conoid ;
55095510 int i_indkey ;
55105511 int i_indisclustered ;
55115512 int i_indnkeys ;
@@ -5539,7 +5540,8 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
55395540 "pg_catalog.pg_get_indexdef(i.indexrelid) as indexdef, "
55405541 "i.indkey, i.indisclustered, "
55415542 "t.relnatts as indnkeys, "
5542- "coalesce(c.contype, '0') as contype "
5543+ "coalesce(c.contype, '0') as contype, "
5544+ "coalesce(c.oid, '0') as conoid "
55435545 "FROM pg_catalog.pg_index i "
55445546 "JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
55455547 "LEFT JOIN pg_catalog.pg_depend d "
@@ -5560,7 +5562,8 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
55605562 "i.indkey, false as indisclustered, "
55615563 "t.relnatts as indnkeys, "
55625564 "CASE WHEN i.indisprimary THEN 'p'::char "
5563- "ELSE '0'::char END as contype "
5565+ "ELSE '0'::char END as contype, "
5566+ "0::oid as conoid "
55645567 "FROM pg_index i, pg_class t "
55655568 "WHERE t.oid = i.indexrelid "
55665569 "AND i.indrelid = '%s'::oid "
@@ -5581,6 +5584,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
55815584 i_indexrelname = PQfnumber (res , "indexrelname" );
55825585 i_indexdef = PQfnumber (res , "indexdef" );
55835586 i_contype = PQfnumber (res , "contype" );
5587+ i_conoid = PQfnumber (res , "conoid" );
55845588 i_indkey = PQfnumber (res , "indkey" );
55855589 i_indisclustered = PQfnumber (res , "indisclustered" );
55865590 i_indnkeys = PQfnumber (res , "indnkeys" );
@@ -5591,6 +5595,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
55915595 const char * indexrelname = PQgetvalue (res , j , i_indexrelname );
55925596 const char * indexdef = PQgetvalue (res , j , i_indexdef );
55935597 char contype = * (PQgetvalue (res , j , i_contype ));
5598+ const char * conoid = PQgetvalue (res , j , i_conoid );
55945599 bool indisclustered = (PQgetvalue (res , j , i_indisclustered )[0 ] == 't' );
55955600
55965601 resetPQExpBuffer (q );
@@ -5634,6 +5639,15 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
56345639
56355640 appendPQExpBuffer (q , ");\n" );
56365641
5642+ /* If the index is clustered, we need to record that. */
5643+ if (indisclustered )
5644+ {
5645+ appendPQExpBuffer (q , "\nALTER TABLE %s CLUSTER" ,
5646+ fmtId (tbinfo -> relname ));
5647+ appendPQExpBuffer (q , " ON %s;\n" ,
5648+ fmtId (indexrelname ));
5649+ }
5650+
56375651 /*
56385652 * DROP must be fully qualified in case same name appears
56395653 * in pg_catalog
@@ -5644,14 +5658,6 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
56445658 fmtId (tbinfo -> relname ));
56455659 appendPQExpBuffer (delq , "DROP CONSTRAINT %s;\n" ,
56465660 fmtId (indexrelname ));
5647- /* If the index is clustered, we need to record that. */
5648- if (indisclustered )
5649- {
5650- appendPQExpBuffer (q , "\nALTER TABLE %s CLUSTER" ,
5651- fmtId (tbinfo -> relname ));
5652- appendPQExpBuffer (q , " ON %s;\n" ,
5653- fmtId (indexrelname ));
5654- }
56555661
56565662 ArchiveEntry (fout , indexreloid ,
56575663 indexrelname ,
@@ -5664,6 +5670,17 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
56645670 for (k = 0 ; k < indnkeys ; k ++ )
56655671 free (indkeys [k ]);
56665672 free (indkeys );
5673+
5674+ /* Dump Constraint Comments */
5675+ resetPQExpBuffer (q );
5676+ appendPQExpBuffer (q , "CONSTRAINT %s " ,
5677+ fmtId (indexrelname ));
5678+ appendPQExpBuffer (q , "ON %s" ,
5679+ fmtId (tbinfo -> relname ));
5680+ dumpComment (fout , q -> data ,
5681+ tbinfo -> relnamespace -> nspname ,
5682+ tbinfo -> usename ,
5683+ conoid , "pg_constraint" , 0 , NULL );
56675684 }
56685685 else
56695686 {
0 commit comments