Re: Move table between schemas

Поиск
Список
Период
Сортировка
От Markus Schaber
Тема Re: Move table between schemas
Дата
Msg-id 20041120114411.28c05fcf@kingfisher.intern.logi-track.com
обсуждение исходный текст
Ответ на Re: Move table between schemas  (Andrew Sullivan <ajs@crankycanuck.ca>)
Ответы Re: Move table between schemas
Список pgsql-sql
Hi, Andrew,

On Tue, 16 Nov 2004 06:05:38 -0500
Andrew Sullivan <ajs@crankycanuck.ca> wrote:

> > Is there an easy way to move a table to another schema in PostgreSQL 7.4?
> >
> > ALTER TABLE and ALTER SCHEMA don't have this options.
>
> CREATE TABLE newschema.newtable AS SELECT * FROM oldschema.oldtable
> oughta work.

This has several drawbacks I can see for now:

- For large tables (some Gigs of data), this needs a long time and
produces heavy I/O load on the server.

- You need twice the disk space until you can delete the old table.

- Indices, triggers, sequences and constraints are not transferred. When
the target schema is first in the search path of the application, this
means that the application works on an incomplete table until I finished
the transition..

- It does not automatically convert views or foreign key constraints
that point to the table.

- The operation is not atomic, thus there may be inserts and updates
into the old table that get lost while the "CREATE...SELECT...;DROP
TABLE...;" runs.


Is there any (possibly ugly, fiddling with system tables) atomic way to
move a table between schemas? It should not be much more difficult
compared to e. G. renaming a table to implement this, so I couuld not
imagine this does not exist until I tried to find out how to do it.


Thanks,
markus
--
markus schaber | dipl. informatiker
logi-track ag | rennweg 14-16 | ch 8001 zürich
phone +41-43-888 62 52 | fax +41-43-888 62 53
mailto:schabios@logi-track.com | www.logi-track.com


В списке pgsql-sql по дате отправления:

Предыдущее
От: Erik Thiele
Дата:
Сообщение: Re: get sequence value of insert command
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Move table between schemas