diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 709e10e..faa3378 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -1162,6 +1162,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) indexdef"); if (verbose) appendPQExpBuffer(&buf, ", a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)"); appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a"); @@ -1230,7 +1232,12 @@ 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"); @@ -1270,6 +1277,10 @@ describeOneTableDetails(const char *schemaname, /* Type */ printTableAddCell(&cont, PQgetvalue(res, i, 1), false); + /* Expression for index */ + if (tableinfo.relkind == 'i') + printTableAddCell(&cont, PQgetvalue(res, i, 5), false); + /* Modifiers: not null and default */ if (show_modifiers) { @@ -2123,9 +2134,29 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys if (showIndexes) appendPQExpBuffer(&buf, - ",\n c2.relname as \"%s\"", - gettext_noop("Table")); + ",\n c2.relname as \"%s\"" + ",\n am.amname as \"%s\"", + gettext_noop("Table"), + gettext_noop("Method")); + if (showIndexes && pset.sversion >= 80400) + appendPQExpBuffer(&buf, + ",\n COALESCE(pg_get_expr(i.indexprs,i.indrelid)," + " (SELECT substr(array_agg(indexdef)::text,2,length(array_agg(indexdef)::text)-2) FROM (\n" + " SELECT pg_get_indexdef(i.indexrelid,a.attnum,TRUE) indexdef\n" + " FROM pg_catalog.pg_attribute a, pg_catalog.pg_index i\n" + " WHERE a.attrelid = c.oid AND a.attnum > 0 AND NOT a.attisdropped AND a.attrelid = i.indexrelid\n" + " GROUP BY i.indexrelid,a.attnum\n" + " ORDER BY a.attnum\n" + " ) agg1)::text) as \"%s\"\n", + gettext_noop("Definition")); + + if (showIndexes && pset.sversion < 80400) + appendPQExpBuffer(&buf, + ",\n COALESCE(pg_get_expr(i.indexprs,i.indrelid)," + " pg_get_indexdef(i.indexrelid,0,TRUE)) as \"%s\"\n", + gettext_noop("Definition")); + if (verbose && pset.sversion >= 80100) appendPQExpBuffer(&buf, ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_relation_size(c.oid)) as \"%s\"", @@ -2141,7 +2172,9 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys if (showIndexes) appendPQExpBuffer(&buf, "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid" - "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid"); + "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid" + "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam" + ); appendPQExpBuffer(&buf, "\nWHERE c.relkind IN ("); if (showTables)