Re: Disabling inheritance with query.

From: Jaime Soler <jaime(dot)soler(at)gmail(dot)com>
To: Francisco Olarte <folarte(at)peoplecall(dot)com>
Cc: Edmundo Robles <edmundo(at)sw-argos(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Disabling inheritance with query.
Date: 2016-12-22 09:55:56
Message-ID: CAKVUGgSAZ0sy2BdFvYbM91CugVxUkej+z4fxp6V2befi-2F4rQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You should use alter table XX NO INHERIT parent_table;

2016-12-22 9:49 GMT+01:00 Francisco Olarte <folarte(at)peoplecall(dot)com>:

> Edmundo:
>
> On Wed, Dec 21, 2016 at 11:36 PM, Edmundo Robles <edmundo(at)sw-argos(dot)com>
> wrote:
> > i need disable inheritance from many tables in a query like
> > "delete from pg_inherits where inhparent=20473" instead alter table ...
> > but is safe? which is the risk for database if i delete it?
>
> Dangers of touching the catalog directly have already been pointed by
> TL, along with the question of why isn't normal ALTER TABLE ok.
>
> If it is because there are a lot of childs, I would like to point a
> simple script ( if you are fluent in any scripting language, or even
> in SQL ) can be used to automatically generate a bunch of alter table
> commands. Even a simple text editor will do ( turn your query above
> into something generating a bunch of table names, edit it ). Or just
> try something like ( beware, untested )
>
> with childs as (select relname from pg_class, pg_inherits where
> pg_class.oid=inhrelid and inhparent='20473)
> SELECT 'ALTER TABLE ' || relname || ' rest of alter table command;'
> from childs ;
>
> And feed the result back to the server using your favorite tool (
> quoting maybe needed, schema names may be needed, YMMV ).
>
> Francisco Olarte.
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Vick Khera 2016-12-22 14:01:13 Re: How well does PostgreSQL 9.6.1 support unicode?
Previous Message Brian Sutherland 2016-12-22 09:23:25 Re: error updating a tuple after promoting a standby