Commit f26e1d39 authored by Bruce Momjian's avatar Bruce Momjian

Add Indices display to \d command.

parent 0b442388
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.149 1998/07/26 01:18:07 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.150 1998/08/04 18:29:41 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -409,11 +409,6 @@ tableList(PsqlSettings *pset, bool deep_tablelist, char info_type, ...@@ -409,11 +409,6 @@ tableList(PsqlSettings *pset, bool deep_tablelist, char info_type,
else else
strcat(listbuf, " and relname ~ '^pg_'"); strcat(listbuf, " and relname ~ '^pg_'");
strcat(listbuf, " and relname !~ '^xin[vx][0-9]+'"); strcat(listbuf, " and relname !~ '^xin[vx][0-9]+'");
/*
* the usesysid = relowner won't work on stock 1.0 dbs, need to add in
* the int4oideq function
*/
strcat(listbuf, " and usesysid = relowner"); strcat(listbuf, " and usesysid = relowner");
strcat(listbuf, " ORDER BY relname "); strcat(listbuf, " ORDER BY relname ");
if (!(res = PSQLexec(pset, listbuf))) if (!(res = PSQLexec(pset, listbuf)))
...@@ -595,6 +590,7 @@ rightsList(PsqlSettings *pset) ...@@ -595,6 +590,7 @@ rightsList(PsqlSettings *pset)
} }
else else
{ {
PQclear(res);
fprintf(stderr, "Couldn't find any tables!\n"); fprintf(stderr, "Couldn't find any tables!\n");
return -1; return -1;
} }
...@@ -611,7 +607,7 @@ int ...@@ -611,7 +607,7 @@ int
tableDesc(PsqlSettings *pset, char *table, FILE *fout) tableDesc(PsqlSettings *pset, char *table, FILE *fout)
{ {
char descbuf[512]; char descbuf[512];
int nColumns; int nColumns, nIndices;
char *rtype; char *rtype;
char *rnotnull; char *rnotnull;
char *rhasdef; char *rhasdef;
...@@ -765,6 +761,40 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout) ...@@ -765,6 +761,40 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
} }
fprintf(fout, "+----------------------------------+----------------------------------+-------+\n"); fprintf(fout, "+----------------------------------+----------------------------------+-------+\n");
PQclear(res); PQclear(res);
/* display defined indexes for this table */
descbuf[0] = '\0';
strcat(descbuf, "SELECT c2.relname ");
strcat(descbuf, "FROM pg_class c, pg_class c2, pg_index i ");
strcat(descbuf, "WHERE c.relname = '");
strcat(descbuf, table);
strcat(descbuf, "'");
strcat(descbuf, " and c.oid = i.indrelid ");
strcat(descbuf, " and i.indexrelid = c2.oid ");
strcat(descbuf, " ORDER BY c2.relname ");
if ((res = PSQLexec(pset, descbuf)))
{
nIndices = PQntuples(res);
if (nIndices > 0)
{
/*
* Display the information
*/
if (nIndices == 1)
fprintf(fout, "Indices: ");
else
fprintf(fout, "Index: ");
/* next, print out the instances */
for (i = 0; i < PQntuples(res); i++)
if (i == 0)
fprintf(fout, "%s\n", PQgetvalue(res, i, 0));
else
fprintf(fout, " %s\n", PQgetvalue(res, i, 0));
}
PQclear(res);
}
if (usePipe) if (usePipe)
{ {
pclose(fout); pclose(fout);
...@@ -774,6 +804,7 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout) ...@@ -774,6 +804,7 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
} }
else else
{ {
PQclear(res);
fprintf(stderr, "Couldn't find table %s!\n", table); fprintf(stderr, "Couldn't find table %s!\n", table);
return -1; return -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment