Home > Archive > PostgreSQL Administration > October 2006 > Re: Copying data from table to table (cloned tables)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Copying data from table to table (cloned tables)
Aaron Bono

2006-10-25, 8:24 am

On 10/10/06, Jim C. Nasby <jim@nasby.net> wrote:
>
> On Mon, Oct 09, 2006 at 05:02:07PM -0700, Bricklen Anderson wrote:
> i
> and
> but
>
> You need to be careful with this method. For what the OP wants to do it
> would probably work, but not always. The problem is that in some
> scenarios, <same criteria as above> won't necessarily return the same
> set of rows.
>
> Starting in 8.2 you'll be able to do something like
>
> INSERT INTO table2 DELET FROM table1 WHERE ... RETURNING *;
>
> The RETURNING * will return all the data that the command deleted. In
> older versions, your best bet is to store the data you're moving in a
> temporary table, and then use that to delete the exact rows.



You may want to lock the table before doing the copy/delete - that would
take care of having a record added between the copy and the delete.

If you are doing this on a regular basis, you may want to consider adding an
insert/update trigger on the original table to put a copy into the secondary
table and then all you have to do is do a simple delete from the originating
table every so often.

--
====================
====================
====================
======
Aaron Bono
Aranya Software Technologies, Inc.
http://www.aranya.com
http://codeelixir.com
====================
====================
====================
======

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com