pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Fetter <david@fetter.org>
Cc: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: Rafia Sabih <rafia.pghackers@gmail.com>
Cc: PostgreSQL Development <pgsql-hackers@postgresql.org>
Subject: Re: [PATCH v5] Show detailed table persistence in \dt+
Date: Tue, 02 Jul 2019 15:10:37 -0400
Message-ID: <4561.1562094637@sss.pgh.pa.us> (raw)
In-Reply-To: <20190429142358.GE2954@fetter.org>
References: <CA+FpmFdx2aDtyiVD2av9+QAunA1L5uscm3dL1SFbcOs8-W678g@mail.gmail.com>
	<CA+FpmFeurtDiutfh2yv0T4S=zY0iegcSStR-5xJ9H7vP2XKQsg@mail.gmail.com>
	<20190427041849.GL28936@fetter.org>
	<alpine.DEB.2.21.1904270844180.29865@lancre>
	<20190427174330.GN28936@fetter.org>
	<alpine.DEB.2.21.1904272214030.29865@lancre>
	<20190428151541.GQ28936@fetter.org>
	<alpine.DEB.2.21.1904281917330.29865@lancre>
	<20190429041902.GC2954@fetter.org>
	<alpine.DEB.2.21.1904290831550.8815@lancre>
	<20190429142358.GE2954@fetter.org>

David Fetter <david@fetter.org> writes:
> [ v7-0001-Show-detailed-relation-persistence-in-dt.patch ]

I looked this over and had a few suggestions, as per attached v8:

* The persistence description values ought to be translatable, as
is the usual practice in describe.c.  This is slightly painful
because it requires tweaking the translate_columns[] values in a
non-constant way, but it's not that bad.

* I dropped the "ELSE 'unknown'" bit in favor of just emitting NULL
if the persistence isn't recognized.  This is the same way that the
table-type CASE just above does it, and I see no reason to be different.
Moreover, there are message-style-guidelines issues with what to print
if you do want to print something; "unknown" doesn't cut it.

* I also dropped the logic for pre-9.1 servers, because the existing
precedent in describeOneTableDetails() is that we only consider
relpersistence for >= 9.1, and I don't see a real good reason to
deviate from that.  9.0 and before are long out of support anyway.

If there aren't objections, I think v8 is committable.

			regards, tom lane

Attachments:

v8-0001-Show-detailed-relation-persistence-in-dt.patch (text/x-diff, 2.0K) download diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 1c770b4..0e0af5f 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. */

view thread (19+ messages)  latest in thread

Message-ID: <4561.1562094637@sss.pgh.pa.us>
Permalink:  ../4561.1562094637@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/4561.1562094637@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david@fetter.org, coelho@cri.ensmp.fr, rafia.pghackers@gmail.com
  Subject: Re: [PATCH v5] Show detailed table persistence in \dt+
  In-Reply-To: <4561.1562094637@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox