Given a postgresql 12 database with some table inheritance, and the child table adds no additional columns:
CREATE TABLE parent (
id integer NOT NULL PRIMARY KEY,
name text NOT NULL
);
CREATE TABLE child () INHERITS (parent);
If I run pg_dump (with pg_dump foo
), the tables look like this in the export:
CREATE TABLE public.parent (
id integer NOT NULL,
name text NOT NULL
);
CREATE TABLE public.child (
)
INHERITS (public.parent);
If I then detach and reattach the child:
$ psql foo
psql (12.1 (Debian 12.1-2))
Type "help" for help.
foo=# ALTER TABLE child NO INHERIT parent;
ALTER TABLE
foo=# ALTER TABLE child INHERIT parent;
ALTER TABLE
... and try another pg_dump, the export has changed. The child table now explicitly lists the columns that are inherited from the parent:
CREATE TABLE public.parent (
id integer NOT NULL,
name text NOT NULL
);
CREATE TABLE public.child (
id integer,
name text
)
INHERITS (public.parent);
Is there anything I can do to get pg_dump to output the child table with no explicit columns?
It sounds like a contrived example, but I have a multi-Tb database that with child tables that have been detached and reattached back in the mists of time, and I'd love the schema exports to go back to being as simple (and readable) as possible.
In particular, it'd be great for everyone to see at a glance that the child table adds no additional columns.