diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-07-03 11:46:34 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-07-03 11:46:34 -0400 |
commit | 9a2ea618323a4cf8ca7eb6a828b08c6e39b95cdd (patch) | |
tree | 0ae390f411f61409dc974bb5a10d35a43c2ec221 /src | |
parent | a5be4062f7bf2ae9487c5a31ee337a56425cdc84 (diff) | |
download | postgresql-9a2ea618323a4cf8ca7eb6a828b08c6e39b95cdd.tar.gz postgresql-9a2ea618323a4cf8ca7eb6a828b08c6e39b95cdd.zip |
Show table persistence in psql's \dt+ and related commands.
In verbose mode, listTables() now emits a "Persistence" column
showing whether the table/index/view/etc is permanent, temporary,
or unlogged.
David Fetter, reviewed by Fabien Coelho and Rafia Sabih
Discussion: https://postgr.es/m/20190423005642.GZ28936@fetter.org
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/psql/describe.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 1c770b4347a..0e0af5f942c 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3632,7 +3632,8 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys PQExpBufferData buf; PGresult *res; printQueryOpt myopt = pset.popt; - static const bool translate_columns[] = {false, false, true, false, false, false, false}; + int cols_so_far; + bool translate_columns[] = {false, false, true, false, false, false, false, false}; /* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */ if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign)) @@ -3672,15 +3673,40 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys gettext_noop("partitioned index"), gettext_noop("Type"), gettext_noop("Owner")); + cols_so_far = 4; if (showIndexes) + { appendPQExpBuffer(&buf, - ",\n c2.relname as \"%s\"", + ",\n c2.relname as \"%s\"", gettext_noop("Table")); + cols_so_far++; + } if (verbose) { /* + * Show whether a relation is permanent, temporary, or unlogged. Like + * describeOneTableDetails(), we consider that persistence emerged in + * v9.1, even though related concepts existed before. + */ + if (pset.sversion >= 90100) + { + appendPQExpBuffer(&buf, + ",\n CASE c.relpersistence WHEN 'p' THEN '%s' WHEN 't' THEN '%s' WHEN 'u' THEN '%s' END as \"%s\"", + gettext_noop("permanent"), + gettext_noop("temporary"), + gettext_noop("unlogged"), + gettext_noop("Persistence")); + translate_columns[cols_so_far] = true; + } + + /* + * We don't bother to count cols_so_far below here, as there's no need + * to; this might change with future additions to the output columns. + */ + + /* * As of PostgreSQL 9.0, use pg_table_size() to show a more accurate * size of a table, including FSM, VM and TOAST tables. */ |