Altering metadata to add inheritance
As an experiement, I want to turn a number of identically structured
tables into "child" tables of a template. That is, I want to do
something like:
alter table foo_01 rename to foo_01_old;
create table foo_01 () inherits (foo_template);
insert into foo_01 select * from foo_01_old;
drop table foo_01_old;
a whole lotta times, for different values of 'foo_01'. I suspect
there's a way to do this directly in the pg_class table. Does anyone
have a tried and safe approach?
jboes@nexcerpt.com (Jeff Boes) writes:
As an experiement, I want to turn a number of identically structured
tables into "child" tables of a template. ... I suspect
there's a way to do this directly in the pg_class table.
pg_class doesn't show inheritance. I *think* all you'd have to do is
insert rows into pg_inherits, see
http://developer.postgresql.org/docs/postgres/catalog-pg-inherits.html
Oh, and you'd have to set pg_class.relhassubclass true for the parent
table.
But I've not tried to do this by hand myself. Better experiment on
a test database ;-)
regards, tom lane