Hi, Andrew, On Tue, 16 Nov 2004 06:05:38 -0500 Andrew Sullivan <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED] | www.logi-track.com ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])