Skip to content

Commit ef6bac3

Browse files
committed
When given a nonzero column number, pg_get_indexdef() is only supposed to
print the index key variable or expression for that column. It was mistakenly printing ASC/DESC/NULLS FIRST/NULLS LAST decoration too --- and not only for the target column, but all columns. Someday we should have an option to extract that info (and the opclass decoration as well) for a single index column ... but today is not that day. Per bug #3829 and subsequent discussion.
1 parent 1b1f7e9 commit ef6bac3

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.266 2007/12/01 23:44:44 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.267 2007/12/20 00:23:19 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -769,25 +769,28 @@ pg_get_indexdef_worker(Oid indexrelid, int colno, bool showTblSpc,
769769
keycoltype = exprType(indexkey);
770770
}
771771

772-
/* Add the operator class name */
772+
/* Provide decoration only in the colno=0 case */
773773
if (!colno)
774+
{
775+
/* Add the operator class name, if not default */
774776
get_opclass_name(indclass->values[keyno], keycoltype, &buf);
775777

776-
/* Add options if relevant */
777-
if (amrec->amcanorder)
778-
{
779-
/* if it supports sort ordering, report DESC and NULLS opts */
780-
if (opt & INDOPTION_DESC)
781-
{
782-
appendStringInfo(&buf, " DESC");
783-
/* NULLS FIRST is the default in this case */
784-
if (!(opt & INDOPTION_NULLS_FIRST))
785-
appendStringInfo(&buf, " NULLS LAST");
786-
}
787-
else
778+
/* Add options if relevant */
779+
if (amrec->amcanorder)
788780
{
789-
if (opt & INDOPTION_NULLS_FIRST)
790-
appendStringInfo(&buf, " NULLS FIRST");
781+
/* if it supports sort ordering, report DESC and NULLS opts */
782+
if (opt & INDOPTION_DESC)
783+
{
784+
appendStringInfo(&buf, " DESC");
785+
/* NULLS FIRST is the default in this case */
786+
if (!(opt & INDOPTION_NULLS_FIRST))
787+
appendStringInfo(&buf, " NULLS LAST");
788+
}
789+
else
790+
{
791+
if (opt & INDOPTION_NULLS_FIRST)
792+
appendStringInfo(&buf, " NULLS FIRST");
793+
}
791794
}
792795
}
793796
}

0 commit comments

Comments
 (0)