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

Commitbf6570a

Browse files
committed
Show definition of index columns in \d on index
This adds a column called "Definition" to the output of psql \d on anindex, which shows the full expression behind the index column. For indexeson plain columns, this is redundant, but for expression indexes, thisreveals the real expression.Author: Khee Chin <kheechin@gmail.com>
1 parent869312e commitbf6570a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

‎src/bin/psql/describe.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
1010
*
11-
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.219 2009/07/03 18:56:50 petere Exp $
11+
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.220 2009/07/06 17:01:42 petere Exp $
1212
*/
1313
#include"postgres_fe.h"
1414

@@ -1163,6 +1163,8 @@ describeOneTableDetails(const char *schemaname,
11631163
"\n FROM pg_catalog.pg_attrdef d"
11641164
"\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),"
11651165
"\n a.attnotnull, a.attnum");
1166+
if (tableinfo.relkind=='i')
1167+
appendPQExpBuffer(&buf,", pg_get_indexdef(i.indexrelid,a.attnum, TRUE) AS indexdef");
11661168
if (verbose)
11671169
appendPQExpBuffer(&buf,", a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)");
11681170
appendPQExpBuffer(&buf,"\nFROM pg_catalog.pg_attribute a");
@@ -1232,6 +1234,9 @@ describeOneTableDetails(const char *schemaname,
12321234
if (tableinfo.relkind=='S')
12331235
headers[cols++]=gettext_noop("Value");
12341236

1237+
if (tableinfo.relkind=='i')
1238+
headers[cols++]=gettext_noop("Definition");
1239+
12351240
if (verbose)
12361241
{
12371242
headers[cols++]=gettext_noop("Storage");
@@ -1297,10 +1302,15 @@ describeOneTableDetails(const char *schemaname,
12971302
if (tableinfo.relkind=='S')
12981303
printTableAddCell(&cont,seq_values[i], false);
12991304

1305+
/* Expression for index */
1306+
if (tableinfo.relkind=='i')
1307+
printTableAddCell(&cont,PQgetvalue(res,i,5), false);
1308+
13001309
/* Storage and Description */
13011310
if (verbose)
13021311
{
1303-
char*storage=PQgetvalue(res,i,5);
1312+
intfnum= (tableinfo.relkind=='i' ?6 :5);
1313+
char*storage=PQgetvalue(res,i,fnum);
13041314

13051315
/* these strings are literal in our syntax, so not translated. */
13061316
printTableAddCell(&cont, (storage[0]=='p' ?"plain" :
@@ -1309,7 +1319,7 @@ describeOneTableDetails(const char *schemaname,
13091319
(storage[0]=='e' ?"external" :
13101320
"???")))),
13111321
false);
1312-
printTableAddCell(&cont,PQgetvalue(res,i,6), false);
1322+
printTableAddCell(&cont,PQgetvalue(res,i,fnum+1), false);
13131323
}
13141324
}
13151325

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp