9
9
*
10
10
*
11
11
* IDENTIFICATION
12
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.305 2009/07/29 20:56:19 tgl Exp $
12
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.306 2009/08/01 19:59:41 tgl Exp $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -142,7 +142,8 @@ static char *pg_get_viewdef_worker(Oid viewoid, int prettyFlags);
142
142
static void decompile_column_index_array (Datum column_index_array ,Oid relId ,
143
143
StringInfo buf );
144
144
static char * pg_get_ruledef_worker (Oid ruleoid ,int prettyFlags );
145
- static char * pg_get_indexdef_worker (Oid indexrelid ,int colno ,bool showTblSpc ,
145
+ static char * pg_get_indexdef_worker (Oid indexrelid ,int colno ,
146
+ bool attrsOnly ,bool showTblSpc ,
146
147
int prettyFlags );
147
148
static char * pg_get_constraintdef_worker (Oid constraintId ,bool fullCommand ,
148
149
int prettyFlags );
@@ -613,7 +614,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
613
614
Oid indexrelid = PG_GETARG_OID (0 );
614
615
615
616
PG_RETURN_TEXT_P (string_to_text (pg_get_indexdef_worker (indexrelid ,0 ,
616
- false,0 )));
617
+ false,false, 0 )));
617
618
}
618
619
619
620
Datum
@@ -626,18 +627,31 @@ pg_get_indexdef_ext(PG_FUNCTION_ARGS)
626
627
627
628
prettyFlags = pretty ?PRETTYFLAG_PAREN |PRETTYFLAG_INDENT :0 ;
628
629
PG_RETURN_TEXT_P (string_to_text (pg_get_indexdef_worker (indexrelid ,colno ,
629
- false,prettyFlags )));
630
+ colno != 0 ,
631
+ false,
632
+ prettyFlags )));
630
633
}
631
634
632
635
/* Internal version that returns a palloc'd C string */
633
636
char *
634
637
pg_get_indexdef_string (Oid indexrelid )
635
638
{
636
- return pg_get_indexdef_worker (indexrelid ,0 , true,0 );
639
+ return pg_get_indexdef_worker (indexrelid ,0 , false, true,0 );
640
+ }
641
+
642
+ /* Internal version that just reports the column definitions */
643
+ char *
644
+ pg_get_indexdef_columns (Oid indexrelid ,bool pretty )
645
+ {
646
+ int prettyFlags ;
647
+
648
+ prettyFlags = pretty ?PRETTYFLAG_PAREN |PRETTYFLAG_INDENT :0 ;
649
+ return pg_get_indexdef_worker (indexrelid ,0 , true, false,prettyFlags );
637
650
}
638
651
639
652
static char *
640
- pg_get_indexdef_worker (Oid indexrelid ,int colno ,bool showTblSpc ,
653
+ pg_get_indexdef_worker (Oid indexrelid ,int colno ,
654
+ bool attrsOnly ,bool showTblSpc ,
641
655
int prettyFlags )
642
656
{
643
657
HeapTuple ht_idx ;
@@ -736,7 +750,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, bool showTblSpc,
736
750
*/
737
751
initStringInfo (& buf );
738
752
739
- if (!colno )
753
+ if (!attrsOnly )
740
754
appendStringInfo (& buf ,"CREATE %sINDEX %s ON %s USING %s (" ,
741
755
idxrec -> indisunique ?"UNIQUE " :"" ,
742
756
quote_identifier (NameStr (idxrelrec -> relname )),
@@ -790,8 +804,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, bool showTblSpc,
790
804
keycoltype = exprType (indexkey );
791
805
}
792
806
793
- /* Provide decoration only in the colno=0 case */
794
- if (!colno )
807
+ if (!attrsOnly && (!colno || colno == keyno + 1 ))
795
808
{
796
809
/* Add the operator class name, if not default */
797
810
get_opclass_name (indclass -> values [keyno ],keycoltype ,& buf );
@@ -816,7 +829,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, bool showTblSpc,
816
829
}
817
830
}
818
831
819
- if (!colno )
832
+ if (!attrsOnly )
820
833
{
821
834
appendStringInfoChar (& buf ,')' );
822
835