From 53571763ca6ead18e70fc7f4ffc33ef13140fd56 Mon Sep 17 00:00:00 2001 From: amit Date: Wed, 8 Mar 2017 11:28:07 +0900 Subject: [PATCH 2/2] Show number of partitions in the \d(+) output even if it's 0 --- src/bin/psql/describe.c | 28 ++++++++++++++++++++++++---- src/test/regress/expected/create_table.out | 2 ++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index f8617cf328..cce7c8859d 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -2707,14 +2707,34 @@ describeOneTableDetails(const char *schemaname, else tuples = PQntuples(result); - if (!verbose) + /* + * If partitioned table, always show the number of partitions, + * even if it's zero. + */ + if (tableinfo.relkind == 'P') { - const char *ct = tableinfo.relkind != 'P' ? _("child tables") : _("partitions"); + /* + * If there are zero partitions, we should always print that. + * Otherwise, print only if verbose is not specified. + */ + if (tuples == 0) + { + printfPQExpBuffer(&buf, _("Number of partitions: %d"), tuples); + printTableAddFooter(&cont, buf.data); + } + else if (!verbose) + { + printfPQExpBuffer(&buf, _("Number of partitions: %d (Use \\d+ to list them.)"), tuples); + printTableAddFooter(&cont, buf.data); + } + } + if (!verbose) + { /* print the number of child tables, if any */ - if (tuples > 0) + if (tableinfo.relkind != 'P' && tuples > 0) { - printfPQExpBuffer(&buf, _("Number of %s: %d (Use \\d+ to list them.)"), ct, tuples); + printfPQExpBuffer(&buf, _("Number of child tables: %d (Use \\d+ to list them.)"), tuples); printTableAddFooter(&cont, buf.data); } } diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index c07a474b3d..19fe113a82 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -440,6 +440,7 @@ ERROR: cannot inherit from partitioned table "partitioned2" c | text | | not null | d | text | | not null | Partition key: RANGE (a oid_ops, plusone(b), c, d COLLATE "C") +Number of partitions: 0 \d partitioned2 Table "public.partitioned2" @@ -447,6 +448,7 @@ Partition key: RANGE (a oid_ops, plusone(b), c, d COLLATE "C") --------+---------+-----------+----------+--------- a | integer | | | Partition key: LIST ((a + 1)) +Number of partitions: 0 DROP TABLE partitioned, partitioned2; -- -- 2.11.0