12
12
* by PostgreSQL
13
13
*
14
14
* 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 $
16
16
*
17
17
*-------------------------------------------------------------------------
18
18
*/
@@ -5506,6 +5506,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5506
5506
int i_indexrelname ;
5507
5507
int i_indexdef ;
5508
5508
int i_contype ;
5509
+ int i_conoid ;
5509
5510
int i_indkey ;
5510
5511
int i_indisclustered ;
5511
5512
int i_indnkeys ;
@@ -5539,7 +5540,8 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5539
5540
"pg_catalog.pg_get_indexdef(i.indexrelid) as indexdef, "
5540
5541
"i.indkey, i.indisclustered, "
5541
5542
"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 "
5543
5545
"FROM pg_catalog.pg_index i "
5544
5546
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
5545
5547
"LEFT JOIN pg_catalog.pg_depend d "
@@ -5560,7 +5562,8 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5560
5562
"i.indkey, false as indisclustered, "
5561
5563
"t.relnatts as indnkeys, "
5562
5564
"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 "
5564
5567
"FROM pg_index i, pg_class t "
5565
5568
"WHERE t.oid = i.indexrelid "
5566
5569
"AND i.indrelid = '%s'::oid "
@@ -5581,6 +5584,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5581
5584
i_indexrelname = PQfnumber (res , "indexrelname" );
5582
5585
i_indexdef = PQfnumber (res , "indexdef" );
5583
5586
i_contype = PQfnumber (res , "contype" );
5587
+ i_conoid = PQfnumber (res , "conoid" );
5584
5588
i_indkey = PQfnumber (res , "indkey" );
5585
5589
i_indisclustered = PQfnumber (res , "indisclustered" );
5586
5590
i_indnkeys = PQfnumber (res , "indnkeys" );
@@ -5591,6 +5595,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5591
5595
const char * indexrelname = PQgetvalue (res , j , i_indexrelname );
5592
5596
const char * indexdef = PQgetvalue (res , j , i_indexdef );
5593
5597
char contype = * (PQgetvalue (res , j , i_contype ));
5598
+ const char * conoid = PQgetvalue (res , j , i_conoid );
5594
5599
bool indisclustered = (PQgetvalue (res , j , i_indisclustered )[0 ] == 't' );
5595
5600
5596
5601
resetPQExpBuffer (q );
@@ -5634,6 +5639,15 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5634
5639
5635
5640
appendPQExpBuffer (q , ");\n" );
5636
5641
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
+
5637
5651
/*
5638
5652
* DROP must be fully qualified in case same name appears
5639
5653
* in pg_catalog
@@ -5644,14 +5658,6 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5644
5658
fmtId (tbinfo -> relname ));
5645
5659
appendPQExpBuffer (delq , "DROP CONSTRAINT %s;\n" ,
5646
5660
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
- }
5655
5661
5656
5662
ArchiveEntry (fout , indexreloid ,
5657
5663
indexrelname ,
@@ -5664,6 +5670,17 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
5664
5670
for (k = 0 ; k < indnkeys ; k ++ )
5665
5671
free (indkeys [k ]);
5666
5672
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 );
5667
5684
}
5668
5685
else
5669
5686
{
0 commit comments