From: Tom Lane <tgl@sss.pgh.pa.us>
To: Markus Schaber <schabios@logi-track.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Move table between schemas
Date: Sat, 20 Nov 2004 11:36:54 -0500
Message-ID: <21309.1100968614@sss.pgh.pa.us> (raw)
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>
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'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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, schabios@logi-track.com
Subject: Re: Move table between schemas
In-Reply-To: <21309.1100968614@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox