Waiting for 8.5 – Have \d show child tables that inherit from the specified parent

Yesterday Peter Eisentraut committed a patch, written by Damien Clochard, that modifies \d output in psql:

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>

How does it look? Quite simple thing to test:

# CREATE TABLE x (id int4);
CREATE TABLE
# CREATE TABLE x2 () INHERITS (x);
CREATE TABLE
# CREATE TABLE x3 () INHERITS (x);
CREATE TABLE

Now, \d of x looks like this:

# \d x
       Table "public.x"
 Column |  Type   | Modifiers
--------+---------+-----------
 id     | integer |
Number of child tables: 2 (Use \d+ to list them.)

Please notice that there is no list of child tables – in some cases you might have hundreds of child tables, so it doesn't make sense to always output them.

Instead, you can:

# \d+ x
                   Table "public.x"
 Column |  Type   | Modifiers | Storage | Description
--------+---------+-----------+---------+-------------
 id     | integer |           | plain   |
Child tables: x2,
              x3
Has OIDs: no

Pretty cool.

5 thoughts on “Waiting for 8.5 – Have \d show child tables that inherit from the specified parent”

  1. I noticed something when making a deeper hierarchy, namely that it descends just one level. I think this may count as a POLA violation. What do you think?

    CREATE TABLE x (id INTEGER);
    CREATE TABLE x_01 () inherits (x);
    CREATE TABLE x_02 () inherits (x);
    CREATE TABLE x_01_01 () inherits (x_01);
    CREATE TABLE x_01_02 () inherits (x_01);

    \d+ x
    Table “public.x”
    Column | Type | Modifiers | Storage | Description
    ——–+———+———–+———+————-
    id | integer | | plain |
    Child tables: x_01,
    x_02
    Has OIDs: no

  2. @David Fetter:
    not sure. I have seen 2 uses for inherited tables so far, and none of them is really useful with multi-level inheritance, but maybe I’m missing some cases.

  3. @depesz
    I’ve seen it in multi-level partitioning schemes. Whether *those* are a good idea is a whole different question.

  4. I think the unfortunate thing about this is that it makes \d+ pretty much unusable on parent tables of large partition schemes.

  5. @Robert

    Yup, I’ll have to remember not to use \d+ on my parent tables with ~7500 children.

Comments are closed.