Skip to content

Commit 5e9f4d2

Browse files
committed
Add CLUSTER tag to psql \d display.
1 parent d8fe99d commit 5e9f4d2

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/bin/psql/describe.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.95 2004/03/22 03:38:24 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.96 2004/04/06 04:05:17 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "describe.h"
@@ -831,7 +831,7 @@ describeOneTableDetails(const char *schemaname,
831831
PGresult *result;
832832

833833
printfPQExpBuffer(&buf,
834-
"SELECT i.indisunique, i.indisprimary, a.amname, c2.relname,\n"
834+
"SELECT i.indisunique, i.indisprimary, i.indisclustered, a.amname, c2.relname,\n"
835835
" pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
836836
"FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
837837
"WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
@@ -850,9 +850,10 @@ describeOneTableDetails(const char *schemaname,
850850
{
851851
char *indisunique = PQgetvalue(result, 0, 0);
852852
char *indisprimary = PQgetvalue(result, 0, 1);
853-
char *indamname = PQgetvalue(result, 0, 2);
854-
char *indtable = PQgetvalue(result, 0, 3);
855-
char *indpred = PQgetvalue(result, 0, 4);
853+
char *indisclustered = PQgetvalue(result, 0, 2);
854+
char *indamname = PQgetvalue(result, 0, 3);
855+
char *indtable = PQgetvalue(result, 0, 4);
856+
char *indpred = PQgetvalue(result, 0, 5);
856857

857858
if (strcmp(indisprimary, "t") == 0)
858859
printfPQExpBuffer(&tmpbuf, _("PRIMARY KEY, "));
@@ -869,6 +870,9 @@ describeOneTableDetails(const char *schemaname,
869870
if (strlen(indpred))
870871
appendPQExpBuffer(&tmpbuf, _(", predicate (%s)"), indpred);
871872

873+
if (strcmp(indisclustered, "t") == 0)
874+
appendPQExpBuffer(&tmpbuf, _(", CLUSTER"));
875+
872876
footers = pg_malloc_zero(2 * sizeof(*footers));
873877
footers[0] = pg_strdup(tmpbuf.data);
874878
footers[1] = NULL;
@@ -948,7 +952,7 @@ describeOneTableDetails(const char *schemaname,
948952
if (tableinfo.hasindex)
949953
{
950954
printfPQExpBuffer(&buf,
951-
"SELECT c2.relname, i.indisprimary, i.indisunique, "
955+
"SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, "
952956
"pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)\n"
953957
"FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
954958
"WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
@@ -1080,15 +1084,17 @@ describeOneTableDetails(const char *schemaname,
10801084
(strcmp(PQgetvalue(result1, i, 2), "t") == 0
10811085
? _(" UNIQUE,")
10821086
: ""));
1083-
10841087
/* Everything after "USING" is echoed verbatim */
1085-
indexdef = PQgetvalue(result1, i, 3);
1088+
indexdef = PQgetvalue(result1, i, 4);
10861089
usingpos = strstr(indexdef, " USING ");
10871090
if (usingpos)
10881091
indexdef = usingpos + 7;
10891092

10901093
appendPQExpBuffer(&buf, " %s", indexdef);
10911094

1095+
if (strcmp(PQgetvalue(result1, i, 3), "t") == 0)
1096+
appendPQExpBuffer(&buf, _(" CLUSTER"));
1097+
10921098
footers[count_footers++] = pg_strdup(buf.data);
10931099
}
10941100
}

0 commit comments

Comments
 (0)