Re: How to add an INHERITS to an already populated table

From: Alvaro Herrera <alvherre(at)surnet(dot)cl>
To: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>
Cc: Richard Huxton <dev(at)archonet(dot)com>, David Pradier <dpradier(at)apartia(dot)fr>, pgsql-general(at)postgresql(dot)org
Subject: Re: How to add an INHERITS to an already populated table
Date: 2005-05-31 13:41:59
Message-ID: 20050531134158.GD5451@surnet.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Pradier 2005-05-31 13:45:24 Re: How to add an INHERITS to an already populated table
Previous Message David Pradier 2005-05-31 13:41:54 Re: How to add an INHERITS to an already populated table