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 E78C93A43FA for ; Sat, 20 Nov 2004 16:37:02 +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 68077-10 for ; Sat, 20 Nov 2004 16:37:00 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 3DBC33A428F for ; Sat, 20 Nov 2004 16:36:59 +0000 (GMT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id iAKGasri021310; Sat, 20 Nov 2004 11:36:54 -0500 (EST) To: Markus Schaber Cc: pgsql-sql@postgresql.org Subject: Re: Move table between schemas In-reply-to: <20041120114411.28c05fcf@kingfisher.intern.logi-track.com> References: <20041116100234.635fcd7e@kingfisher.intern.logi-track.com> <20041116110538.GA15247@phlogiston.dyndns.org> <20041120114411.28c05fcf@kingfisher.intern.logi-track.com> Comments: In-reply-to Markus Schaber message dated "Sat, 20 Nov 2004 11:44:11 +0100" Date: Sat, 20 Nov 2004 11:36:54 -0500 Message-ID: <21309.1100968614@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/212 X-Sequence-Number: 19531 Markus Schaber writes: > Andrew Sullivan 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's rowtype (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