From c5eb296c534c37f990f1b8ba769983acf7c974a2 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 3 Jul 2009 18:56:50 +0000 Subject: [PATCH] Have \d show child tables that inherit from the specified parent As per discussion, \d shows only the number of child tables, because that could be hundreds, when used for partitioning. \d+ shows the actual list. Author: Damien Clochard --- src/bin/psql/describe.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 65d22f2b15..af803d75e5 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -1814,6 +1814,44 @@ describeOneTableDetails(const char *schemaname, } PQclear(result); + /* print child tables */ + printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhrelid AND i.inhparent = '%s' ORDER BY c.oid::pg_catalog.regclass;", oid); + + result = PSQLexec(buf.data, false); + if (!result) + goto error_return; + else + tuples = PQntuples(result); + + if (!verbose) + { + /* print the number of child tables, if any */ + if (tuples > 0) + { + printfPQExpBuffer(&buf, _("Number of child tables: %d (Use \\d+ to list them.)"), tuples); + printTableAddFooter(&cont, buf.data); + } + } + else + { + /* display the list of child tables*/ + for (i = 0; i < tuples; i++) + { + const char *ct = _("Child tables"); + + if (i == 0) + printfPQExpBuffer(&buf, "%s: %s", ct, PQgetvalue(result, i, 0)); + else + printfPQExpBuffer(&buf, "%*s %s", (int) strlen(ct), "", PQgetvalue(result, i, 0)); + if (i < tuples - 1) + appendPQExpBuffer(&buf, ","); + + printTableAddFooter(&cont, buf.data); + } + } + PQclear(result); + + /* OIDs and options */ if (verbose) { const char *s = _("Has OIDs"); -- 2.39.5