Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hiOB3-0003yd-0u for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jul 2019 19:10:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hiOB0-0006ch-Fo for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Jul 2019 19:10:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hiOB0-0006ca-4H for pgsql-hackers@lists.postgresql.org; Tue, 02 Jul 2019 19:10:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hiOAu-0003OP-Bn for pgsql-hackers@postgresql.org; Tue, 02 Jul 2019 19:10:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x62JAbrB004562; Tue, 2 Jul 2019 15:10:38 -0400 From: Tom Lane To: David Fetter cc: Fabien COELHO , Rafia Sabih , PostgreSQL Development Subject: Re: [PATCH v5] Show detailed table persistence in \dt+ In-reply-to: <20190429142358.GE2954@fetter.org> References: <20190427041849.GL28936@fetter.org> <20190427174330.GN28936@fetter.org> <20190428151541.GQ28936@fetter.org> <20190429041902.GC2954@fetter.org> <20190429142358.GE2954@fetter.org> Comments: In-reply-to David Fetter message dated "Mon, 29 Apr 2019 16:23:58 +0200" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <4497.1562094570.0@sss.pgh.pa.us> Date: Tue, 02 Jul 2019 15:10:37 -0400 Message-ID: <4561.1562094637@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4497.1562094570.1@sss.pgh.pa.us> David Fetter 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 ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="v8-0001-Show-detailed-relation-persistence-in-dt.patch"; charset="us-ascii" Content-ID: <4497.1562094570.2@sss.pgh.pa.us> Content-Description: v8-0001-Show-detailed-relation-persistence-in-dt.patch Content-Transfer-Encoding: quoted-printable 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 =3D pset.popt; - static const bool translate_columns[] =3D {false, false, true, false, fa= lse, false, false}; + int cols_so_far; + bool translate_columns[] =3D {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 *patte= rn, bool verbose, bool showSys gettext_noop("partitioned index"), gettext_noop("Type"), gettext_noop("Owner")); + cols_so_far =3D 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 >=3D 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] =3D 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. */ ------- =_aaaaaaaaaa0--