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)
Bricklen Anderson

2006-10-25, 8:24 am

Fourat Zouari wrote:
> Hello all,
> Any one could suggest the best way to copy data from table to table in
> the same db, the reason why am seeking for this is that the first table
> is becoming very big, and old data has no reason why to stay there, so i
> created a cloned table but without indexes and constraints (lighter) and
> now i would like to copy 'some' data from first to second table (copied
> data is data older than 3 months, i have a timestamp column).
>
> In other way, i have a table called 'hotqueues' where i store fresh
> messages queued, once messages are treated, they stay in 'hotqueues' but
> with a flag indicating that their arent queued for treatment..
> so in this way, data will rest there forever, slowing down any searches
> in that table, the solution was to copy old messages to another table
> called 'coldqueues' that has the same structure as 'hotqueues' but
> lighter (without constraints and indexes).
> How to copy these data with 100% data-loose free.
>
> Thanks for any help you can provide.


If you just want to copy the data across to the other table:
begin;
insert into table2 select * from table1 where <some criteria>;
commit;

if you also want to remove that same data from table1:
begin;
insert into table2 select * from table1 where <some criteria>;
delete from table1 where <same criteria as above>;
commit;

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

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