diff options
author | Peter Eisentraut | 2009-07-06 17:01:42 +0000 |
---|---|---|
committer | Peter Eisentraut | 2009-07-06 17:01:42 +0000 |
commit | 6ce778c6500222286bf03631b6ee479de1bdda99 (patch) | |
tree | bef54e459016e59e726bdf6125e07f2fe738800e | |
parent | 4b25a7ef2b4bdbf160393c881bece7597baea1d3 (diff) |
Show definition of index columns in \d on index
This adds a column called "Definition" to the output of psql \d on an
index, which shows the full expression behind the index column. For indexes
on plain columns, this is redundant, but for expression indexes, this
reveals the real expression.
Author: Khee Chin <[email protected]>
-rw-r--r-- | src/bin/psql/describe.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index af803d75e5..d176685fdc 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -1163,6 +1163,8 @@ describeOneTableDetails(const char *schemaname, "\n FROM pg_catalog.pg_attrdef d" "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)," "\n a.attnotnull, a.attnum"); + if (tableinfo.relkind == 'i') + appendPQExpBuffer(&buf, ", pg_get_indexdef(i.indexrelid,a.attnum, TRUE) AS indexdef"); if (verbose) appendPQExpBuffer(&buf, ", a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)"); appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a"); @@ -1232,6 +1234,9 @@ describeOneTableDetails(const char *schemaname, if (tableinfo.relkind == 'S') headers[cols++] = gettext_noop("Value"); + if (tableinfo.relkind == 'i') + headers[cols++] = gettext_noop("Definition"); + if (verbose) { headers[cols++] = gettext_noop("Storage"); @@ -1297,10 +1302,15 @@ describeOneTableDetails(const char *schemaname, if (tableinfo.relkind == 'S') printTableAddCell(&cont, seq_values[i], false); + /* Expression for index */ + if (tableinfo.relkind == 'i') + printTableAddCell(&cont, PQgetvalue(res, i, 5), false); + /* Storage and Description */ if (verbose) { - char *storage = PQgetvalue(res, i, 5); + int fnum = (tableinfo.relkind == 'i' ? 6 : 5); + char *storage = PQgetvalue(res, i, fnum); /* these strings are literal in our syntax, so not translated. */ printTableAddCell(&cont, (storage[0] == 'p' ? "plain" : @@ -1309,7 +1319,7 @@ describeOneTableDetails(const char *schemaname, (storage[0] == 'e' ? "external" : "???")))), false); - printTableAddCell(&cont, PQgetvalue(res, i, 6), false); + printTableAddCell(&cont, PQgetvalue(res, i, fnum + 1), false); } } |