Re: Have \d show child tables that inherit from the specified parent - Mailing list pgsql-hackers
From | damien@dalibo.info |
---|---|
Subject | Re: Have \d show child tables that inherit from the specified parent |
Date | |
Msg-id | 4A061A5C.3030108@dalibo.info Whole thread Raw |
In response to | Re: Have \d show child tables that inherit from the specified parent ("Greg Sabino Mullane" <greg@turnstep.com>) |
Responses |
Re: Have \d show child tables that inherit from the specified parent
Re: Have \d show child tables that inherit from the specified parent |
List | pgsql-hackers |
Hi, Here's a second version. Main changes are : * Child tables are sorted by name * \d only shows the number of child tables * \d+ shows the full list Which gives : postgres=# \d mother Table "public.mother" Column | Type | Modifiers --------+---------+----------------------------------------------------- id | integer | not null default nextval('mother_id_seq'::regclass) This table has 4 child table(s). Use \d+ to display them. postgres=# \d+ mother Table "public.mother" Column | Type | Modifiers | Storage | Description --------+---------+-----------------------------------------------------+---------+------------- id | integer | not null default nextval('mother_id_seq'::regclass) | plain | Child tables: daughter, daughter2, daughter3, plop.daughter4 Has OIDs: no For people having hundreds of child tables, the use of \d+ will still be uncomfortable. But i must admit that i can't see any better way to implement this feature, except by adding a new syntax ( \dh to show specific information about inheritance ? ) Anyway let me know if you think it is not worth going forward on that feature :-) -- damien clochard http://dalibo.org | http://dalibo.com ? logfile Index: describe.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/bin/psql/describe.c,v retrieving revision 1.212 diff -c -r1.212 describe.c *** describe.c 5 May 2009 02:29:06 -0000 1.212 --- describe.c 9 May 2009 23:57:36 -0000 *************** *** 1812,1817 **** --- 1812,1856 ---- } PQclear(result); + /* print child tables */ + printfPQExpBuffer(&buf, "SELECT c.oid::pg_catalog.regclass FROM pg_catalog.pg_class c, pg_catalog.pg_inherits iWHERE 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, _("This table has %i child table(s). Use \\d+ to display 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); + + + if (verbose) { const char *s = _("Has OIDs");
pgsql-hackers by date: