Re: How to add an INHERITS to an already populated table - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: How to add an INHERITS to an already populated table
Date
Msg-id 20050531134158.GD5451@surnet.cl
Whole thread Raw
In response to Re: How to add an INHERITS to an already populated table  (Oleg Bartunov <oleg@sai.msu.su>)
Responses Re: How to add an INHERITS to an already populated table
List pgsql-general
On Tue, May 31, 2005 at 04:53:46PM +0400, Oleg Bartunov wrote:
> On Tue, 31 May 2005, Oleg Bartunov wrote:
>
> >look on pg_inherits table and pg_class.relhassubclass.
> >More info http://www.pgsql.ru/db/mw/msg.html?mid=2044343
> >
>
> example:
>
> create table t (i int4);
> create table t1 (i int4);
> create table t2 (i int4);
>
> -- mark 't' has children tables
> update pg_class set relhassubclass='t' where relname='t';
> -- get oid of child table 't1'
> select relfilenode from pg_class where relname='t1';
> -- get oid of parent table
> select relfilenode from pg_class where relname='t';
> -- add inheritance t-t1
> insert into pg_inherits values(15769046,15769044,1);
> -- get oid of child table 't2'
> select relfilenode from pg_class where relname='t2';
> -- add inheritance t-t2
> insert into pg_inherits values(15769048,15769044,1);

Please note that the inheritance is not fully set -- if you discover
strange behavior e.g. when altering any of the tables, don't be
surprised.  In particular, you should set the attislocal and attinhcount
attributes in pg_attribute for the child tables; also pg_depend entries
are missing.  I don't know what else.

Also you definitely shouldn't be using relfilenode, but the real Oid of
the table (relfilenode is the filename only, not the internal identifier
of the table).

--
Alvaro Herrera (<alvherre[a]surnet.cl>)
Essentially, you're proposing Kevlar shoes as a solution for the problem
that you want to walk around carrying a loaded gun aimed at your foot.
(Tom Lane)

pgsql-general by date:

Previous
From: David Pradier
Date:
Subject: Re: How to add an INHERITS to an already populated table
Next
From: David Pradier
Date:
Subject: Re: How to add an INHERITS to an already populated table