From: Bruce Momjian Date: Fri, 25 Jul 2003 21:42:26 +0000 (+0000) Subject: > Having read the list, and noticed the message about table inheritance I X-Git-Tag: REL7_4_BETA1~126 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57748fc25d95d1daa8a251c01e9014361c36c1b2;p=postgresql > Having read the list, and noticed the message about table inheritance I > thought that I would see if I could come up with a simple solution, and > have my first delve into the code for PostgreSQL. > > Attached is a diff against 7.3.3 source, of changes to describe.c for > psql. This should print out a list of parent tables in a similar style > to that of the index listing. I have done some testing on my side and it > all seems fine, can some other people have a quick look? What do people > think? Useful? Nick Barr --- diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c index 7edb1d3b01..c44b527bb0 100644 --- a/src/bin/psql/describe.c +++ b/src/bin/psql/describe.c @@ -3,7 +3,7 @@ * * Copyright 2000-2002 by PostgreSQL Global Development Group * - * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.79 2003/07/23 08:47:39 petere Exp $ + * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.80 2003/07/25 21:42:26 momjian Exp $ */ #include "postgres_fe.h" #include "describe.h" @@ -928,12 +928,14 @@ describeOneTableDetails(const char *schemaname, *result2 = NULL, *result3 = NULL, *result4 = NULL, - *result5 = NULL; + *result5 = NULL, + *result6 = NULL; int check_count = 0, index_count = 0, foreignkey_count = 0, rule_count = 0, - trigger_count = 0; + trigger_count = 0, + inherits_count = 0; int count_footers = 0; /* count indexes */ @@ -1037,7 +1039,16 @@ describeOneTableDetails(const char *schemaname, foreignkey_count = PQntuples(result5); } - footers = xmalloczero((index_count + check_count + rule_count + trigger_count + foreignkey_count + 6) + /* count inherited tables */ + printfPQExpBuffer(&buf, "SELECT c.relname FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i WHERE c.oid=i.inhparent AND i.inhrelid = '%s' ORDER BY inhseqno ASC", oid); + + result6 = PSQLexec(buf.data, false); + if (!result6) + goto error_return; + else + inherits_count = PQntuples(result6); + + footers = xmalloczero((index_count + check_count + rule_count + trigger_count + foreignkey_count + inherits_count + 6) * sizeof(*footers)); /* print indexes */ @@ -1140,6 +1151,21 @@ describeOneTableDetails(const char *schemaname, } } + /* print inherits */ + for (i = 0; i < inherits_count; i++) + { + char *s = _("Inherits"); + + if (i == 0) + printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result6, i, 0)); + else + printfPQExpBuffer(&buf, "%*s %s", (int) strlen(s), "", PQgetvalue(result6, i, 0)); + if (i < inherits_count - 1) + appendPQExpBuffer(&buf, ","); + + footers[count_footers++] = xstrdup(buf.data); + } + /* end of list marker */ footers[count_footers] = NULL; @@ -1148,6 +1174,7 @@ describeOneTableDetails(const char *schemaname, PQclear(result3); PQclear(result4); PQclear(result5); + PQclear(result6); } printTable(title.data, headers,