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" );
11661168if (verbose )
11671169appendPQExpBuffer (& buf ,", a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)" );
11681170appendPQExpBuffer (& buf ,"\nFROM pg_catalog.pg_attribute a" );
@@ -1232,6 +1234,9 @@ describeOneTableDetails(const char *schemaname,
12321234if (tableinfo .relkind == 'S' )
12331235headers [cols ++ ]= gettext_noop ("Value" );
12341236
1237+ if (tableinfo .relkind == 'i' )
1238+ headers [cols ++ ]= gettext_noop ("Definition" );
1239+
12351240if (verbose )
12361241{
12371242headers [cols ++ ]= gettext_noop ("Storage" );
@@ -1297,10 +1302,15 @@ describeOneTableDetails(const char *schemaname,
12971302if (tableinfo .relkind == 'S' )
12981303printTableAddCell (& 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 */
13011310if (verbose )
13021311{
1303- char * storage = PQgetvalue (res ,i ,5 );
1312+ int fnum = (tableinfo .relkind == 'i' ?6 :5 );
1313+ char * storage = PQgetvalue (res ,i ,fnum );
13041314
13051315/* these strings are literal in our syntax, so not translated. */
13061316printTableAddCell (& 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