Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9a2ea61

Browse files
committed
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
1 parent a5be406 commit 9a2ea61

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/bin/psql/describe.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,7 +3632,8 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
36323632
PQExpBufferData buf;
36333633
PGresult *res;
36343634
printQueryOpt myopt = pset.popt;
3635-
static const bool translate_columns[] = {false, false, true, false, false, false, false};
3635+
int cols_so_far;
3636+
bool translate_columns[] = {false, false, true, false, false, false, false, false};
36363637

36373638
/* If tabtypes is empty, we default to \dtvmsE (but see also command.c) */
36383639
if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
@@ -3672,14 +3673,39 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
36723673
gettext_noop("partitioned index"),
36733674
gettext_noop("Type"),
36743675
gettext_noop("Owner"));
3676+
cols_so_far = 4;
36753677

36763678
if (showIndexes)
3679+
{
36773680
appendPQExpBuffer(&buf,
3678-
",\n c2.relname as \"%s\"",
3681+
",\n c2.relname as \"%s\"",
36793682
gettext_noop("Table"));
3683+
cols_so_far++;
3684+
}
36803685

36813686
if (verbose)
36823687
{
3688+
/*
3689+
* Show whether a relation is permanent, temporary, or unlogged. Like
3690+
* describeOneTableDetails(), we consider that persistence emerged in
3691+
* v9.1, even though related concepts existed before.
3692+
*/
3693+
if (pset.sversion >= 90100)
3694+
{
3695+
appendPQExpBuffer(&buf,
3696+
",\n CASE c.relpersistence WHEN 'p' THEN '%s' WHEN 't' THEN '%s' WHEN 'u' THEN '%s' END as \"%s\"",
3697+
gettext_noop("permanent"),
3698+
gettext_noop("temporary"),
3699+
gettext_noop("unlogged"),
3700+
gettext_noop("Persistence"));
3701+
translate_columns[cols_so_far] = true;
3702+
}
3703+
3704+
/*
3705+
* We don't bother to count cols_so_far below here, as there's no need
3706+
* to; this might change with future additions to the output columns.
3707+
*/
3708+
36833709
/*
36843710
* As of PostgreSQL 9.0, use pg_table_size() to show a more accurate
36853711
* size of a table, including FSM, VM and TOAST tables.

0 commit comments

Comments
 (0)