From 6ce778c6500222286bf03631b6ee479de1bdda99 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 6 Jul 2009 17:01:42 +0000 Subject: [PATCH] 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 --- src/bin/psql/describe.c | 14 ++++++++++++-- 1 file 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); } } -- 2.39.5