move data from one table to another, postgresql edition
Posted
by IggShaman
on Stack Overflow
See other posts from Stack Overflow
or by IggShaman
Published on 2010-06-04T12:27:44Z
Indexed on
2010/06/05
9:32 UTC
Read the original article
Hit count: 192
sql
|postgresql
Hi All,
I'd like to move some data from one table to another (with a possibly different schema). Straightforward solution that comes into mind is -
start a transaction with serializable isolation level;
INSERT INTO dest_table SELECT data FROM orig_table,other-tables WHERE <condition>;
DELETE FROM orig_table USING other-tables WHERE <condition>;
COMMIT;
Now what if the amount of data is rather big, and the <condition>
is expensive to compute? In PostgreSQL, a RULE or a stored procedure can be used to delete data on the fly, evaluating condition only once. Which solution is better? Are there other options?
© Stack Overflow or respective owner