99 *
1010 *
1111 * 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 $
1313 *
1414 *-------------------------------------------------------------------------
1515 */
@@ -142,7 +142,8 @@ static char *pg_get_viewdef_worker(Oid viewoid, int prettyFlags);
142142static void decompile_column_index_array (Datum column_index_array , Oid relId ,
143143 StringInfo buf );
144144static 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 ,
146147 int prettyFlags );
147148static char * pg_get_constraintdef_worker (Oid constraintId , bool fullCommand ,
148149 int prettyFlags );
@@ -613,7 +614,7 @@ pg_get_indexdef(PG_FUNCTION_ARGS)
613614 Oid indexrelid = PG_GETARG_OID (0 );
614615
615616 PG_RETURN_TEXT_P (string_to_text (pg_get_indexdef_worker (indexrelid , 0 ,
616- false, 0 )));
617+ false, false, 0 )));
617618}
618619
619620Datum
@@ -626,18 +627,31 @@ pg_get_indexdef_ext(PG_FUNCTION_ARGS)
626627
627628 prettyFlags = pretty ? PRETTYFLAG_PAREN | PRETTYFLAG_INDENT : 0 ;
628629 PG_RETURN_TEXT_P (string_to_text (pg_get_indexdef_worker (indexrelid , colno ,
629- false, prettyFlags )));
630+ colno != 0 ,
631+ false,
632+ prettyFlags )));
630633}
631634
632635/* Internal version that returns a palloc'd C string */
633636char *
634637pg_get_indexdef_string (Oid indexrelid )
635638{
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 );
637650}
638651
639652static 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 ,
641655 int prettyFlags )
642656{
643657 HeapTuple ht_idx ;
@@ -736,7 +750,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, bool showTblSpc,
736750 */
737751 initStringInfo (& buf );
738752
739- if (!colno )
753+ if (!attrsOnly )
740754 appendStringInfo (& buf , "CREATE %sINDEX %s ON %s USING %s (" ,
741755 idxrec -> indisunique ? "UNIQUE " : "" ,
742756 quote_identifier (NameStr (idxrelrec -> relname )),
@@ -790,8 +804,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, bool showTblSpc,
790804 keycoltype = exprType (indexkey );
791805 }
792806
793- /* Provide decoration only in the colno=0 case */
794- if (!colno )
807+ if (!attrsOnly && (!colno || colno == keyno + 1 ))
795808 {
796809 /* Add the operator class name, if not default */
797810 get_opclass_name (indclass -> values [keyno ], keycoltype , & buf );
@@ -816,7 +829,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, bool showTblSpc,
816829 }
817830 }
818831
819- if (!colno )
832+ if (!attrsOnly )
820833 {
821834 appendStringInfoChar (& buf , ')' );
822835
0 commit comments