Re: transfering tables into other schema

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: transfering tables into other schema
Date: 2009-02-17 17:20:54
Message-ID: 20090217182054.5d5417fa@dawn.webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 17 Feb 2009 12:19:14 +0000
Sam Mason <sam(at)samason(dot)me(dot)uk> wrote:

> > > I'd like to move all the 200 tables to a new schema and leave
> > > that one in the public schema.
> >
> > ALTER TABLE name SET SCHEMA new_schema;
>
> Make sure your functions don't contain any hard coded references to
> the old schema name though!
>
> As Raymond says, you can do this all in a transaction and roll
> back if any of the functions don't do the correct thing. Be aware
> that you're probably going to lock other users out when doing this
> so it may be worth having a script (so it's locked for as small a
> time as possible and doesn't wait for human amounts of time) that
> renames the schema and runs a few of the functions with
> representative arguments and a rollback at the end. Once you've
> run this a few times with different functions and arguments and
> generally convinced yourself that all is OK, change the rollback
> to commit and all will be done.

I can't get how this really work.
You're saying that constraint, fk/pk relationships will be preserved
automatically... what else?

OK BEFORE:

create table x (
xid primary key,
...
);
create table y (
xid int referencex x (xid),
...
);

-- following in application
select x.a, y.b from x join y on x.xid=y.xid;

-- following in the DB
create or replace function xy() as
$$
begin
select x.a, y.b from x join y on x.xid=y.xid;
...
end;
$$ ...

ALTER TABLE y SET SCHEMA new_schema;

What should I change by hand?

thanks

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Marc G. Fournier 2009-02-17 17:21:23 Re: [GENERAL] 8.3 doc issue
Previous Message Alvaro Herrera 2009-02-17 17:20:22 Re: [GENERAL] 8.3 doc issue