On 2017/07/12 13:09, Amit Langote wrote:
> On 2017/07/12 12:47, Ashutosh Bapat wrote:
>> Do you see that those patches can be used in current discussion in any way?
>
> It wouldn't really be a bad idea to put that patch here, because there's
> no special reason for it to be in the CF for PG 11, if we are talking here
> about changing \d command outputs anyway.
So, here are 4 patches (including the 2 patches that Ashutosh linked to
upthread):
0001: Show relispartition=true relations as "(foreign) partition" and
RELKIND_PARTITIONED_TABLE relations that are not themselves
partitions as "partitioned table"
0002: Hide relispartition=true relations (partitions) by default in the
\d listing (that is, \d without a name pattern); to enable
displaying partitions, add a modifier '++'
0003: In \d+ partitioned_table output (describe partitioned table showing
individual partitions), show if the individual partitions are
partitioned themselves if it actually does have partitions
currently
0004: In \d+ partitioned_table output, do not skip the portion of the
output showing information about partitions if there are currently
no partitions defined; instead show "Number of partitions: 0"
Regarding 0001, while it shows "partition" and "partitioned table" in the
Type column of \d listing, \d name_pattern will still show Table
"schemaname.tablename". For example:
\d
List of relations
Schema | Name | Type | Owner
--------+-------+-------------------+-------
public | xyz | partitioned table | amit
public | xyz1 | partition | amit
public | xyz2 | partition | amit
public | xyz3 | partition | amit
public | xyz31 | partition | amit
(5 rows)
\d xyz*
Table "public.xyz"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+---------
a | integer | | |
Partition key: LIST (a)
Number of partitions: 3 (Use \d+ to list them.)
Table "public.xyz1"
<snip>
Table "public.xyz2"
<snip>
Table "public.xyz3"
<snip>
Table "public.xyz31"
<snip>
...which might seem kind of odd. Do we want to show xyz1 as "Partition
public.xyz1", for example?
Thanks,
Amit
From ceacc566ab7ac2ffe56a47435a53a12ebafdffe5 Mon Sep 17 00:00:00 2001
From: amit <[email protected]>
Date: Mon, 10 Jul 2017 13:25:20 +0900
Subject: [PATCH 1/4] Show partitions and partitioned tables as such in \d
listing
---
src/bin/psql/describe.c | 51 ++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 42 insertions(+), 9 deletions(-)
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index e6833eced5..4613490f56 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -3321,27 +3321,60 @@ listTables(const char *tabtypes, const char *pattern,
bool verbose, bool showSys
printfPQExpBuffer(&buf,
"SELECT n.nspname as \"%s\",\n"
" c.relname as \"%s\",\n"
- " CASE c.relkind"
- " WHEN "
CppAsString2(RELKIND_RELATION) " THEN '%s'"
+ " CASE c.relkind",
+ gettext_noop("Schema"),
+ gettext_noop("Name"));
+
+ /*
+ * Starting in PG 10, certain kinds of relations could be partitions,
which
+ * if so, we show Type accordingly.
+ */
+ if (pset.sversion >= 100000)
+ appendPQExpBuffer(&buf,
+ " WHEN "
CppAsString2(RELKIND_RELATION) " THEN"
+ " CASE c.relispartition"
+ " WHEN 'true' THEN '%s'
ELSE '%s'"
+ " END"
+
+ " WHEN "
CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN"
+ " CASE c.relispartition"
+ " WHEN 'true' THEN '%s'
ELSE '%s'"
+ " END"
+
+ " WHEN "
CppAsString2(RELKIND_FOREIGN_TABLE) " THEN"
+ " CASE c.relispartition"
+ " WHEN 'true' THEN '%s'
ELSE '%s'"
+ " END",
+ gettext_noop("partition"),
+ gettext_noop("table"),
+
+ gettext_noop("partition"),
+ gettext_noop("partitioned
table"),
+
+ gettext_noop("foreign
partition"),
+ gettext_noop("foreign
table"));
+ else
+ appendPQExpBuffer(&buf,
+ " WHEN "
CppAsString2(RELKIND_RELATION) " THEN '%s'"
+ " WHEN "
CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
+ " WHEN "
CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'",
+ gettext_noop("table"),
+ gettext_noop("partitioned
table"),
+ gettext_noop("foreign
table"));
+
+ appendPQExpBuffer(&buf,
" WHEN " CppAsString2(RELKIND_VIEW) "
THEN '%s'"
" WHEN "
CppAsString2(RELKIND_MATVIEW) " THEN '%s'"
" WHEN " CppAsString2(RELKIND_INDEX)
" THEN '%s'"
" WHEN "
CppAsString2(RELKIND_SEQUENCE) " THEN '%s'"
" WHEN 's' THEN '%s'"
- " WHEN "
CppAsString2(RELKIND_FOREIGN_TABLE) " THEN '%s'"
- " WHEN "
CppAsString2(RELKIND_PARTITIONED_TABLE) " THEN '%s'"
" END as \"%s\",\n"
"
pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
- gettext_noop("Schema"),
- gettext_noop("Name"),
- gettext_noop("table"),
gettext_noop("view"),
gettext_noop("materialized view"),
gettext_noop("index"),
gettext_noop("sequence"),
gettext_noop("special"),
- gettext_noop("foreign table"),
- gettext_noop("table"), /*
partitioned table */
gettext_noop("Type"),
gettext_noop("Owner"));
--
2.11.0
From 32e3a030fcc3642c8af3dfae0c40869f8377299b Mon Sep 17 00:00:00 2001
From: amit <[email protected]>
Date: Mon, 10 Jul 2017 13:57:47 +0900
Subject: [PATCH 2/4] Exclude partitions by default from the the psql \d
listing
Add a new modifier '!' to \d to request listing partitions.
---
doc/src/sgml/ref/psql-ref.sgml | 14 +++++++++-----
src/bin/psql/command.c | 13 +++++++++----
src/bin/psql/describe.c | 12 ++++++++++--
src/bin/psql/describe.h | 4 ++--
src/bin/psql/help.c | 12 ++++++------
5 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index c592edac60..8bb2f5bb0c 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1096,7 +1096,7 @@ testdb=>
<varlistentry>
- <term><literal>\d[S+] [ <link linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
+ <term><literal>\d[S{+|++}] [ <link
linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
<listitem>
<para>
@@ -1132,7 +1132,9 @@ testdb=>
<para>
By default, only user-created objects are shown; supply a
pattern or the <literal>S</literal> modifier to include system
- objects.
+ objects. Also, by default, only non-partition objects are shown;
+ supply a pattern or the <literal>!</literal> modifier to include
+ partitions.
</para>
<note>
@@ -1296,11 +1298,11 @@ testdb=>
<varlistentry>
- <term><literal>\dE[S+] [ <link
linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
+ <term><literal>\dE[S{+|++}] [ <link
linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
<term><literal>\di[S+] [ <link
linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
<term><literal>\dm[S+] [ <link
linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
<term><literal>\ds[S+] [ <link
linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
- <term><literal>\dt[S+] [ <link
linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
+ <term><literal>\dt[S{+|++}] [ <link
linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
<term><literal>\dv[S+] [ <link
linkend="APP-PSQL-patterns"><replaceable
class="parameter">pattern</replaceable></link> ]</literal></term>
<listitem>
@@ -1320,7 +1322,9 @@ testdb=>
specified, only objects whose names match the pattern are listed.
By default, only user-created objects are shown; supply a
pattern or the <literal>S</literal> modifier to include system
- objects.
+ objects. Also, by default, only non-partition objects are shown;
+ supply a pattern or the <literal>++</literal> modifier to include
+ partitions.
</para>
</listitem>
</varlistentry>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 14c64208ca..07a4e7d0ac 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -703,7 +703,8 @@ exec_command_d(PsqlScanState scan_state, bool
active_branch, const char *cmd)
{
char *pattern;
bool show_verbose,
- show_system;
+ show_system,
+ show_partitions;
/* We don't do SQLID reduction on the pattern yet */
pattern = psql_scan_slash_option(scan_state,
@@ -711,6 +712,7 @@ exec_command_d(PsqlScanState scan_state, bool
active_branch, const char *cmd)
show_verbose = strchr(cmd, '+') ? true : false;
show_system = strchr(cmd, 'S') ? true : false;
+ show_partitions = strstr(cmd, "++") ? true : false;
switch (cmd[1])
{
@@ -718,10 +720,12 @@ exec_command_d(PsqlScanState scan_state, bool
active_branch, const char *cmd)
case '+':
case 'S':
if (pattern)
- success = describeTableDetails(pattern,
show_verbose, show_system);
+ success = describeTableDetails(pattern,
show_verbose, show_system,
+
show_partitions);
else
/* standard listing of interesting
things */
- success = listTables("tvmsE", NULL,
show_verbose, show_system);
+ success = listTables("tvmsE", NULL,
show_verbose, show_system,
+
show_partitions);
break;
case 'A':
success = describeAccessMethods(pattern,
show_verbose);
@@ -795,7 +799,8 @@ exec_command_d(PsqlScanState scan_state, bool
active_branch, const char *cmd)
case 'i':
case 's':
case 'E':
- success = listTables(&cmd[1], pattern,
show_verbose, show_system);
+ success = listTables(&cmd[1], pattern,
show_verbose, show_system,
+
show_partitions);
break;
case 'r':
if (cmd[2] == 'd' && cmd[3] == 's')
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 4613490f56..86adfb71b7 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -1284,7 +1284,8 @@ objectDescription(const char *pattern, bool showSystem)
* verbose: if true, this is \d+
*/
bool
-describeTableDetails(const char *pattern, bool verbose, bool showSystem)
+describeTableDetails(const char *pattern, bool verbose, bool showSystem,
+ bool showPartitions)
{
PQExpBufferData buf;
PGresult *res;
@@ -1303,6 +1304,9 @@ describeTableDetails(const char *pattern, bool verbose,
bool showSystem)
appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
" AND n.nspname
<> 'information_schema'\n");
+ if (pset.sversion >= 100000 && !showPartitions && !pattern)
+ appendPQExpBufferStr(&buf, " AND relispartition =
false\n");
+
processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern,
false,
"n.nspname", "c.relname",
NULL,
"pg_catalog.pg_table_is_visible(c.oid)");
@@ -3294,7 +3298,8 @@ listDbRoleSettings(const char *pattern, const char
*pattern2)
* (any order of the above is fine)
*/
bool
-listTables(const char *tabtypes, const char *pattern, bool verbose, bool
showSystem)
+listTables(const char *tabtypes, const char *pattern, bool verbose, bool
showSystem,
+ bool showPartitions)
{
bool showTables = strchr(tabtypes, 't') != NULL;
bool showIndexes = strchr(tabtypes, 'i') != NULL;
@@ -3444,6 +3449,9 @@ listTables(const char *tabtypes, const char *pattern,
bool verbose, bool showSys
*/
appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
+ if (pset.sversion >= 100000 && !showPartitions)
+ appendPQExpBufferStr(&buf, " AND relispartition =
'false'\n");
+
processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "c.relname",
NULL,
"pg_catalog.pg_table_is_visible(c.oid)");
diff --git a/src/bin/psql/describe.h b/src/bin/psql/describe.h
index 14a5667f3e..f48c505798 100644
--- a/src/bin/psql/describe.h
+++ b/src/bin/psql/describe.h
@@ -43,7 +43,7 @@ extern bool listDefaultACLs(const char *pattern);
extern bool objectDescription(const char *pattern, bool showSystem);
/* \d foo */
-extern bool describeTableDetails(const char *pattern, bool verbose, bool
showSystem);
+extern bool describeTableDetails(const char *pattern, bool verbose, bool
showSystem, bool showPartitions);
/* \dF */
extern bool listTSConfigs(const char *pattern, bool verbose);
@@ -61,7 +61,7 @@ extern bool listTSTemplates(const char *pattern, bool
verbose);
extern bool listAllDbs(const char *pattern, bool verbose);
/* \dt, \di, \ds, \dS, etc. */
-extern bool listTables(const char *tabtypes, const char *pattern, bool
verbose, bool showSystem);
+extern bool listTables(const char *tabtypes, const char *pattern, bool
verbose, bool showSystem, bool showPartitions);
/* \dD */
extern bool listDomains(const char *pattern, bool verbose, bool showSystem);
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index b3dbb5946e..d0603f6436 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -218,9 +218,9 @@ slashUsage(unsigned short int pager)
fprintf(output, "\n");
fprintf(output, _("Informational\n"));
- fprintf(output, _(" (options: S = show system objects, + = additional
detail)\n"));
- fprintf(output, _(" \\d[S+] list tables, views, and
sequences\n"));
- fprintf(output, _(" \\d[S+] NAME describe table, view,
sequence, or index\n"));
+ fprintf(output, _(" (options: S = show system objects, + = additional
detail, ++ = show partitions)\n"));
+ fprintf(output, _(" \\d[S{+|++}] list tables, views, and
sequences\n"));
+ fprintf(output, _(" \\d[S{+|++}] NAME describe table, view,
sequence, or index\n"));
fprintf(output, _(" \\da[S] [PATTERN] list aggregates\n"));
fprintf(output, _(" \\dA[+] [PATTERN] list access methods\n"));
fprintf(output, _(" \\db[+] [PATTERN] list tablespaces\n"));
@@ -229,8 +229,8 @@ slashUsage(unsigned short int pager)
fprintf(output, _(" \\dd[S] [PATTERN] show object descriptions
not displayed elsewhere\n"));
fprintf(output, _(" \\dD[S+] [PATTERN] list domains\n"));
fprintf(output, _(" \\ddp [PATTERN] list default
privileges\n"));
- fprintf(output, _(" \\dE[S+] [PATTERN] list foreign tables\n"));
- fprintf(output, _(" \\det[+] [PATTERN] list foreign tables\n"));
+ fprintf(output, _(" \\dE[S{+|++}] [PATTERN] list foreign tables\n"));
+ fprintf(output, _(" \\det[{+|++}] [PATTERN] list foreign tables\n"));
fprintf(output, _(" \\des[+] [PATTERN] list foreign servers\n"));
fprintf(output, _(" \\deu[+] [PATTERN] list user mappings\n"));
fprintf(output, _(" \\dew[+] [PATTERN] list foreign-data
wrappers\n"));
@@ -252,7 +252,7 @@ slashUsage(unsigned short int pager)
fprintf(output, _(" \\dRp[+] [PATTERN] list replication
publications\n"));
fprintf(output, _(" \\dRs[+] [PATTERN] list replication
subscriptions\n"));
fprintf(output, _(" \\ds[S+] [PATTERN] list sequences\n"));
- fprintf(output, _(" \\dt[S+] [PATTERN] list tables\n"));
+ fprintf(output, _(" \\dt[S{+|++}] [PATTERN] list tables\n"));
fprintf(output, _(" \\dT[S+] [PATTERN] list data types\n"));
fprintf(output, _(" \\du[S+] [PATTERN] list roles\n"));
fprintf(output, _(" \\dv[S+] [PATTERN] list views\n"));
--
2.11.0
From adbe3b01da876ea506dbffedc7188c3ebfd46e42 Mon Sep 17 00:00:00 2001
From: amit <[email protected]>
Date: Wed, 12 Jul 2017 15:24:07 +0900
Subject: [PATCH 3/4] Indicate whether a partition is itself partitioned in \d+
output
That's done by appending a " has partitions" string to the line
describing an individual partition.
Authors: Amit Langote, Ashutosh Bapat
---
src/bin/psql/describe.c | 37 +++++++++++++++++++++++++-----------
src/test/regress/expected/insert.out | 15 +++++++++++++++
src/test/regress/sql/insert.sql | 4 ++++
3 files changed, 45 insertions(+), 11 deletions(-)
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 86adfb71b7..faf69b95c6 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -2838,7 +2838,9 @@ describeOneTableDetails(const char *schemaname,
/* print child tables (with additional info if partitions) */
if (pset.sversion >= 100000)
printfPQExpBuffer(&buf,
- "SELECT
c.oid::pg_catalog.regclass, pg_get_expr(c.relpartbound, c.oid)"
+ "SELECT
c.oid::pg_catalog.regclass,"
+ "
pg_get_expr(c.relpartbound, c.oid),"
+ " c.relkind"
" FROM
pg_catalog.pg_class c, pg_catalog.pg_inherits i"
" WHERE
c.oid=i.inhrelid AND"
" i.inhparent = '%s'
AND"
@@ -2863,21 +2865,25 @@ describeOneTableDetails(const char *schemaname,
if (!verbose)
{
+ const char *ct = (tableinfo.relkind !=
RELKIND_PARTITIONED_TABLE)
+ ?
_("child tables")
+ :
_("partitions");
+
/* print the number of child tables, if any */
if (tuples > 0)
{
- if (tableinfo.relkind !=
RELKIND_PARTITIONED_TABLE)
- printfPQExpBuffer(&buf, _("Number of
child tables: %d (Use \\d+ to list them.)"), tuples);
- else
- printfPQExpBuffer(&buf, _("Number of
partitions: %d (Use \\d+ to list them.)"), tuples);
+ printfPQExpBuffer(&buf,
+ _("Number of %s: %d
(Use \\d+ to list them.)"),
+ ct, tuples);
printTableAddFooter(&cont, buf.data);
}
}
else
{
/* display the list of child tables */
- const char *ct = (tableinfo.relkind !=
RELKIND_PARTITIONED_TABLE) ?
- _("Child tables") : _("Partitions");
+ const char *ct = (tableinfo.relkind !=
RELKIND_PARTITIONED_TABLE)
+ ?
_("Child tables")
+ :
_("Partitions");
int ctw = pg_wcswidth(ct,
strlen(ct), pset.encoding);
for (i = 0; i < tuples; i++)
@@ -2893,12 +2899,21 @@ describeOneTableDetails(const char *schemaname,
}
else
{
+ char *partitioned_note;
+
+ if (*PQgetvalue(result, i, 2) ==
RELKIND_PARTITIONED_TABLE)
+ partitioned_note = " has
partitions";
+ else
+ partitioned_note = "";
+
if (i == 0)
- printfPQExpBuffer(&buf, "%s: %s
%s",
-
ct, PQgetvalue(result, i, 0), PQgetvalue(result, i, 1));
+ printfPQExpBuffer(&buf, "%s: %s
%s%s",
+
ct, PQgetvalue(result, i, 0), PQgetvalue(result, i, 1),
+
partitioned_note);
else
- printfPQExpBuffer(&buf, "%*s
%s %s",
-
ctw, "", PQgetvalue(result, i, 0), PQgetvalue(result, i, 1));
+ printfPQExpBuffer(&buf, "%*s
%s %s%s",
+
ctw, "", PQgetvalue(result, i, 0), PQgetvalue(result, i, 1),
+
partitioned_note);
}
if (i < tuples - 1)
appendPQExpBufferChar(&buf, ',');
diff --git a/src/test/regress/expected/insert.out
b/src/test/regress/expected/insert.out
index d1153f410b..210a158521 100644
--- a/src/test/regress/expected/insert.out
+++ b/src/test/regress/expected/insert.out
@@ -314,6 +314,21 @@ select tableoid::regclass::text, a, min(b) as min_b,
max(b) as max_b from list_p
part_null | | 1 | 1
(9 rows)
+-- test \d+ output on a table which has both partitioned and unpartitioned
+-- partitions
+\d+ list_parted
+ Table "public.list_parted"
+ Column | Type | Collation | Nullable | Default | Storage | Stats target |
Description
+--------+---------+-----------+----------+---------+----------+--------------+-------------
+ a | text | | | | extended | |
+ b | integer | | | | plain | |
+Partition key: LIST (lower(a))
+Partitions: part_aa_bb FOR VALUES IN ('aa', 'bb'),
+ part_cc_dd FOR VALUES IN ('cc', 'dd'),
+ part_ee_ff FOR VALUES IN ('ee', 'ff') has partitions,
+ part_gg FOR VALUES IN ('gg') has partitions,
+ part_null FOR VALUES IN (NULL)
+
-- cleanup
drop table range_parted, list_parted;
-- more tests for certain multi-level partitioning scenarios
diff --git a/src/test/regress/sql/insert.sql b/src/test/regress/sql/insert.sql
index 83c3ad8f53..3c67692ace 100644
--- a/src/test/regress/sql/insert.sql
+++ b/src/test/regress/sql/insert.sql
@@ -185,6 +185,10 @@ insert into list_parted select 'gg', s.a from
generate_series(1, 9) s(a);
insert into list_parted (b) values (1);
select tableoid::regclass::text, a, min(b) as min_b, max(b) as max_b from
list_parted group by 1, 2 order by 1;
+-- test \d+ output on a table which has both partitioned and unpartitioned
+-- partitions
+\d+ list_parted
+
-- cleanup
drop table range_parted, list_parted;
--
2.11.0
From d42522fb19d74a4154d3310a667a82ca888e0bf9 Mon Sep 17 00:00:00 2001
From: amit <[email protected]>
Date: Wed, 12 Jul 2017 15:37:29 +0900
Subject: [PATCH 4/4] Fix \d+ output for yet empty partitioned tables
Currently it only shows the partition key line, but says nothing
about partitions. Instead add a line saying it has 0 partitions.
Authors: Amit Langote, Ashutosh Bapat
---
src/bin/psql/describe.c | 16 +++++++++++++++-
src/test/regress/expected/create_table.out | 13 ++++++++-----
src/test/regress/expected/foreign_data.out | 3 +++
src/test/regress/sql/create_table.sql | 2 +-
4 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index faf69b95c6..28b0f2b62a 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -2863,7 +2863,20 @@ describeOneTableDetails(const char *schemaname,
else
tuples = PQntuples(result);
- if (!verbose)
+ /*
+ * For a partitioned table with no partitions, always print the
number
+ * of partitions as zero, even when verbose output is expected.
+ * Otherwise, we will not print "Partitions" section for a
partitioned
+ * table without any partitions.
+ */
+ if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE && tuples ==
0)
+ {
+
+ /* print the number of child tables, if any */
+ printfPQExpBuffer(&buf, _("Number of partitions: %d"),
tuples);
+ printTableAddFooter(&cont, buf.data);
+ }
+ else if (!verbose)
{
const char *ct = (tableinfo.relkind !=
RELKIND_PARTITIONED_TABLE)
?
_("child tables")
@@ -2921,6 +2934,7 @@ describeOneTableDetails(const char *schemaname,
printTableAddFooter(&cont, buf.data);
}
}
+
PQclear(result);
/* Table type */
diff --git a/src/test/regress/expected/create_table.out
b/src/test/regress/expected/create_table.out
index b6f794e1c2..f6c6a514fa 100644
--- a/src/test/regress/expected/create_table.out
+++ b/src/test/regress/expected/create_table.out
@@ -428,13 +428,15 @@ ERROR: cannot inherit from partitioned table
"partitioned2"
c | text | | |
d | text | | |
Partition key: RANGE (a oid_ops, plusone(b), c, d COLLATE "C")
+Number of partitions: 0
-\d partitioned2
- Table "public.partitioned2"
- Column | Type | Collation | Nullable | Default
---------+---------+-----------+----------+---------
- a | integer | | |
+\d+ partitioned2
+ Table "public.partitioned2"
+ Column | Type | Collation | Nullable | Default | Storage | Stats target |
Description
+--------+---------+-----------+----------+---------+---------+--------------+-------------
+ a | integer | | | | plain | |
Partition key: LIST ((a + 1))
+Number of partitions: 0
DROP TABLE partitioned, partitioned2;
--
@@ -773,5 +775,6 @@ SELECT obj_description('parted_col_comment'::regclass);
a | integer | | | | plain | |
Partition key
b | text | | | | extended | |
Partition key: LIST (a)
+Number of partitions: 0
DROP TABLE parted_col_comment;
diff --git a/src/test/regress/expected/foreign_data.out
b/src/test/regress/expected/foreign_data.out
index 7f2f529393..51da5e91e2 100644
--- a/src/test/regress/expected/foreign_data.out
+++ b/src/test/regress/expected/foreign_data.out
@@ -1879,6 +1879,7 @@ DROP FOREIGN TABLE pt2_1;
c2 | text | | | | extended | |
c3 | date | | | | plain | |
Partition key: LIST (c1)
+Number of partitions: 0
CREATE FOREIGN TABLE pt2_1 (
c1 integer NOT NULL,
@@ -1963,6 +1964,7 @@ ALTER TABLE pt2 ALTER c2 SET NOT NULL;
c2 | text | | not null | | extended | |
c3 | date | | | | plain | |
Partition key: LIST (c1)
+Number of partitions: 0
\d+ pt2_1
Foreign table "public.pt2_1"
@@ -1992,6 +1994,7 @@ ALTER TABLE pt2 ADD CONSTRAINT pt2chk1 CHECK (c1 > 0);
Partition key: LIST (c1)
Check constraints:
"pt2chk1" CHECK (c1 > 0)
+Number of partitions: 0
\d+ pt2_1
Foreign table "public.pt2_1"
diff --git a/src/test/regress/sql/create_table.sql
b/src/test/regress/sql/create_table.sql
index cb7aa5bbc6..80106dd7d9 100644
--- a/src/test/regress/sql/create_table.sql
+++ b/src/test/regress/sql/create_table.sql
@@ -421,7 +421,7 @@ CREATE TABLE fail () INHERITS (partitioned2);
-- Partition key in describe output
\d partitioned
-\d partitioned2
+\d+ partitioned2
DROP TABLE partitioned, partitioned2;
--
2.11.0
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers