Skip to content

Commit 4cba72c

Browse files
committed
Show index predicate when doing \d on a partial index.
1 parent e8f1097 commit 4cba72c

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

src/bin/psql/describe.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.35 2001/07/08 14:42:17 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.36 2001/08/05 22:13:46 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "describe.h"
@@ -27,8 +27,8 @@
2727
*/
2828

2929
/* the maximal size of regular expression we'll accept here */
30-
/* (it is save to just change this here) */
31-
#define REGEXP_CUTOFF 10 * NAMEDATALEN
30+
/* (it is safe to just change this here) */
31+
#define REGEXP_CUTOFF (10 * NAMEDATALEN)
3232

3333

3434
/* \da
@@ -637,49 +637,65 @@ describeTableDetails(const char *name, bool desc)
637637
}
638638

639639
/* Make footers */
640-
/* Information about the index */
641640
if (tableinfo.relkind == 'i')
642641
{
642+
/* Footer information about an index */
643643
PGresult *result;
644644

645-
sprintf(buf, "SELECT i.indisunique, i.indisprimary, i.indislossy, a.amname\n"
645+
sprintf(buf, "SELECT i.indisunique, i.indisprimary, i.indislossy, a.amname,\n"
646+
" pg_get_expr(i.indpred, i.indrelid) as indpred\n"
646647
"FROM pg_index i, pg_class c, pg_am a\n"
647648
"WHERE i.indexrelid = c.oid AND c.relname = '%s' AND c.relam = a.oid",
648649
name);
649650

650651
result = PSQLexec(buf);
651-
if (!result)
652+
if (!result || PQntuples(result) != 1)
652653
error = true;
653654
else
654655
{
656+
char *indisunique = PQgetvalue(result, 0, 0);
657+
char *indisprimary = PQgetvalue(result, 0, 1);
658+
char *indislossy = PQgetvalue(result, 0, 2);
659+
char *indamname = PQgetvalue(result, 0, 3);
660+
char *indpred = PQgetvalue(result, 0, 4);
661+
662+
footers = xmalloc(3 * sizeof(*footers));
655663
/* XXX This construction is poorly internationalized. */
656-
footers = xmalloc(2 * sizeof(*footers));
657664
footers[0] = xmalloc(NAMEDATALEN + 128);
658-
snprintf(footers[0], NAMEDATALEN + 128, "%s%s%s",
659-
strcmp(PQgetvalue(result, 0, 0), "t") == 0 ? _("unique ") : "",
660-
PQgetvalue(result, 0, 3),
661-
strcmp(PQgetvalue(result, 0, 2), "t") == 0 ? _(" (lossy)") : ""
662-
);
663-
if (strcmp(PQgetvalue(result, 0, 1), "t") == 0)
665+
snprintf(footers[0], NAMEDATALEN + 128, "%s%s",
666+
strcmp(indisunique, "t") == 0 ? _("unique ") : "",
667+
indamname);
668+
if (strcmp(indisprimary, "t") == 0)
664669
snprintf(footers[0] + strlen(footers[0]),
665670
NAMEDATALEN + 128 - strlen(footers[0]),
666671
_(" (primary key)"));
667-
footers[1] = NULL;
672+
if (strcmp(indislossy, "t") == 0)
673+
snprintf(footers[0] + strlen(footers[0]),
674+
NAMEDATALEN + 128 - strlen(footers[0]),
675+
_(" (lossy)"));
676+
if (strlen(indpred) > 0)
677+
{
678+
footers[1] = xmalloc(64 + strlen(indpred));
679+
snprintf(footers[1], 64 + strlen(indpred),
680+
_("Index predicate: %s"), indpred);
681+
footers[2] = NULL;
682+
}
683+
else
684+
footers[1] = NULL;
668685
}
669686
}
670-
/* Information about the view */
671687
else if (view_def)
672688
{
689+
/* Footer information about a view */
673690
footers = xmalloc(2 * sizeof(*footers));
674691
footers[0] = xmalloc(64 + strlen(view_def));
675692
snprintf(footers[0], 64 + strlen(view_def),
676693
_("View definition: %s"), view_def);
677694
footers[1] = NULL;
678695
}
679-
680-
/* Information about the table */
681696
else if (tableinfo.relkind == 'r')
682697
{
698+
/* Footer information about a table */
683699
PGresult *result1 = NULL,
684700
*result2 = NULL,
685701
*result3 = NULL,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy