Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf26e1d3

Browse files
committed
Add Indices display to \d command.
1 parent0b44238 commitf26e1d3

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

‎src/bin/psql/psql.c

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.149 1998/07/26 01:18:07 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.150 1998/08/0418:29:41 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -408,12 +408,7 @@ tableList(PsqlSettings *pset, bool deep_tablelist, char info_type,
408408
strcat(listbuf," and relname !~ '^pg_'");
409409
else
410410
strcat(listbuf," and relname ~ '^pg_'");
411-
strcat(listbuf," and relname !~ '^xin[vx][0-9]+'");
412-
413-
/*
414-
* the usesysid = relowner won't work on stock 1.0 dbs, need to add in
415-
* the int4oideq function
416-
*/
411+
strcat(listbuf," and relname !~ '^xin[vx][0-9]+'");
417412
strcat(listbuf," and usesysid = relowner");
418413
strcat(listbuf," ORDER BY relname ");
419414
if (!(res=PSQLexec(pset,listbuf)))
@@ -595,6 +590,7 @@ rightsList(PsqlSettings *pset)
595590
}
596591
else
597592
{
593+
PQclear(res);
598594
fprintf(stderr,"Couldn't find any tables!\n");
599595
return-1;
600596
}
@@ -611,7 +607,7 @@ int
611607
tableDesc(PsqlSettings*pset,char*table,FILE*fout)
612608
{
613609
chardescbuf[512];
614-
intnColumns;
610+
intnColumns,nIndices;
615611
char*rtype;
616612
char*rnotnull;
617613
char*rhasdef;
@@ -765,6 +761,40 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
765761
}
766762
fprintf(fout,"+----------------------------------+----------------------------------+-------+\n");
767763
PQclear(res);
764+
765+
/* display defined indexes for this table */
766+
descbuf[0]='\0';
767+
strcat(descbuf,"SELECT c2.relname ");
768+
strcat(descbuf,"FROM pg_class c, pg_class c2, pg_index i ");
769+
strcat(descbuf,"WHERE c.relname = '");
770+
strcat(descbuf,table);
771+
strcat(descbuf,"'");
772+
strcat(descbuf," and c.oid = i.indrelid ");
773+
strcat(descbuf," and i.indexrelid = c2.oid ");
774+
strcat(descbuf," ORDER BY c2.relname ");
775+
if ((res=PSQLexec(pset,descbuf)))
776+
{
777+
nIndices=PQntuples(res);
778+
if (nIndices>0)
779+
{
780+
/*
781+
* Display the information
782+
*/
783+
784+
if (nIndices==1)
785+
fprintf(fout,"Indices: ");
786+
else
787+
fprintf(fout,"Index: ");
788+
789+
/* next, print out the instances */
790+
for (i=0;i<PQntuples(res);i++)
791+
if (i==0)
792+
fprintf(fout,"%s\n",PQgetvalue(res,i,0));
793+
else
794+
fprintf(fout," %s\n",PQgetvalue(res,i,0));
795+
}
796+
PQclear(res);
797+
}
768798
if (usePipe)
769799
{
770800
pclose(fout);
@@ -774,6 +804,7 @@ tableDesc(PsqlSettings *pset, char *table, FILE *fout)
774804
}
775805
else
776806
{
807+
PQclear(res);
777808
fprintf(stderr,"Couldn't find table %s!\n",table);
778809
return-1;
779810
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp