aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2009-07-03 18:56:50 +0000
committerPeter Eisentraut <peter_e@gmx.net>2009-07-03 18:56:50 +0000
commite2b42aef53da08dfdcd30b5ffee543b65993ae3d (patch)
treea948cfee8dd9fca4abb718c1a11cec8a208a0237 /src
parent53fa850c80f347c967339df7f53d24ca1a669164 (diff)
downloadpostgresql-e2b42aef53da08dfdcd30b5ffee543b65993ae3d.tar.gz
postgresql-e2b42aef53da08dfdcd30b5ffee543b65993ae3d.zip
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 <damien@dalibo.info>
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/describe.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index cde2428259d..751af1c3792 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -8,7 +8,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.218 2009/06/13 13:43:34 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.219 2009/07/03 18:56:50 petere Exp $
*/
#include "postgres_fe.h"
@@ -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");