Have \d show child tables that inherit from the specified parent

Поиск
Список
Период
Сортировка
От damien clochard
Тема Have \d show child tables that inherit from the specified parent
Дата
Msg-id 49A5D354.7000609@dalibo.info
обсуждение исходный текст
Ответы Re: Have \d show child tables that inherit from the specified parent  (David Fetter <david@fetter.org>)
Re: Have \d show child tables that inherit from the specified parent  ("Greg Sabino Mullane" <greg@turnstep.com>)
Список pgsql-hackers
Hello,

Last week, i took some time to check if i was still able to write some
basic C code. So i looked into the TODO list and picked some trivial items.

This one is very basic, it just shows the child tables of a specific
table when you type \d <tablename> in psql :


# create table mother(id SERIAL);
# create table daughter() inherits(mother);
# create table daughter2() inherits(mother);
# create schema plop;
# create table plop.daughter3() inherits(mother);
# \d mother
                         Table "public.mother"
 Column |  Type   |                      Modifiers
--------+---------+-----------------------------------------------------
 id     | integer | not null default nextval('mother_id_seq'::regclass)
Child tables: daughter,
              daughter2,
              plop.daughter3


I understand that it may not be the best moment to submit such a trivial
patch, as most of you are working hard on more important topics. If you
think i should submit it later, just let me know.

BTW, this is the first patch i submit so any comment is more than welcome.

Regards,

--
damien clochard
dalibo.com | dalibo.org
? logfile
? psql
Index: describe.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/describe.c,v
retrieving revision 1.199
diff -c -r1.199 describe.c
*** describe.c    11 Feb 2009 19:12:04 -0000    1.199
--- describe.c    25 Feb 2009 22:53:50 -0000
***************
*** 1668,1673 ****
--- 1668,1699 ----
          }
          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 i.inhseqno;", oid); 
+
+                 result = PSQLexec(buf.data, false);
+                 if (!result)
+                         goto error_return;
+                 else
+                         tuples = PQntuples(result);
+
+                 for (i = 0; i < tuples; i++)
+                 {
+                         const char *s = _("Child tables");
+
+                         if (i == 0)
+                                 printfPQExpBuffer(&buf, "%s: %s", s, PQgetvalue(result, i, 0));
+                         else
+                                 printfPQExpBuffer(&buf, "%*s  %s", (int) strlen(s), "", 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 по дате отправления:

Предыдущее
От: "Kevin Grittner"
Дата:
Сообщение: effective_cache_size less than shared_buffers
Следующее
От: "Joshua D. Drake"
Дата:
Сообщение: Re: effective_cache_size less than shared_buffers