X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 22B073A4C73 for ; Sat, 20 Nov 2004 10:44:37 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 89034-09 for ; Sat, 20 Nov 2004 10:44:27 +0000 (GMT) Received: from mail.logi-track.com (burro.logi-track.com [213.239.193.212]) by svr1.postgresql.org (Postfix) with ESMTP id 4534C3A3FFF for ; Sat, 20 Nov 2004 10:44:28 +0000 (GMT) Received: from kingfisher.intern.logi-track.com (p5088F44C.dip0.t-ipconnect.de [80.136.244.76]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.logi-track.com (Postfix) with ESMTP id A1D9A30033; Sat, 20 Nov 2004 11:44:28 +0100 (CET) Received: from kingfisher.intern.logi-track.com (localhost [127.0.0.1]) by kingfisher.intern.logi-track.com (Postfix) with SMTP id 19013AB0D0; Sat, 20 Nov 2004 11:44:12 +0100 (CET) Date: Sat, 20 Nov 2004 11:44:11 +0100 From: Markus Schaber To: pgsql-sql@postgresql.org Subject: Re: Move table between schemas Message-ID: <20041120114411.28c05fcf@kingfisher.intern.logi-track.com> In-Reply-To: <20041116110538.GA15247@phlogiston.dyndns.org> References: <20041116100234.635fcd7e@kingfisher.intern.logi-track.com> <20041116110538.GA15247@phlogiston.dyndns.org> Organization: logi-track ag, =?ISO-8859-15?Q?z=FCrich?= X-Mailer: Sylpheed-Claws 0.9.12b (GTK+ 1.2.10; i386-pc-linux-gnu) X-Face: Nx5T&>Nj$VrVPv}sC3IL&)TqHHOKCz/|)R$i"*r@w0{*I6w; UNU_hdl1J4NI_m{IMztq=>cmM}1gCLbAF+9\#CGkG8}Y{x%SuQ>1#t:; Z(|\qdd[i]HStki~#w1$TPF}:0w-7"S\Ev|_a$K wrote: > > Is there an easy way to move a table to another schema in PostgreSQL 7.= 4? > >=20 > > ALTER TABLE and ALTER SCHEMA don't have this options. >=20 > CREATE TABLE newschema.newtable AS SELECT * FROM oldschema.oldtable=20 > 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 --=20 markus schaber | dipl. informatiker logi-track ag | rennweg 14-16 | ch 8001 z=FCrich phone +41-43-888 62 52 | fax +41-43-888 62 53 mailto:schabios@logi-track.com | www.logi-track.com