Re: Move table between schemas

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Move table between schemas
Дата
Msg-id 21309.1100968614@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Move table between schemas  (Markus Schaber <schabios@logi-track.com>)
Список pgsql-sql
Markus Schaber <schabios@logi-track.com> writes:
> Andrew Sullivan <ajs@crankycanuck.ca> wrote:
>> CREATE TABLE newschema.newtable AS SELECT * FROM oldschema.oldtable 
>> oughta work.

> - 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.

You'd deal with that by taking a lock on the old table.  Any sort of
catalog-munging solution would have to do the same (though admittedly it
wouldn't need to hold the lock as long).

> Is there any (possibly ugly, fiddling with system tables) atomic way to
> move a table between schemas?

Offhand:* update table's pg_class.relnamespace field* update pg_depend entry that links table to namespace* repeat for
table'srowtype (pg_type entry)* repeat for each index on the table* repeat for each constraint on the table
 

Not sure if that's all the places or not...
        regards, tom lane


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

Предыдущее
От: Markus Schaber
Дата:
Сообщение: Re: Move table between schemas
Следующее
От: Rodrigo Carvalhaes
Дата:
Сообщение: How to get the max on a char column?