pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bricklen Anderson <banderson@presinet.com>
To: Fourat Zouari <fourat@gmail.com>
Cc: pgsql-novice@postgresql.org
Cc: pgsql-admin@postgresql.org
Subject: Re: Copying data from table to table (cloned tables)
Date: Mon, 09 Oct 2006 17:02:07 -0700
Message-ID: <452AE2FF.1020409@presinet.com> (raw)
In-Reply-To: <621eda8a0610091651oc78994fy2b358260f5c9b58a@mail.gmail.com>
References: <621eda8a0610091651oc78994fy2b358260f5c9b58a@mail.gmail.com>

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;



view thread (13+ messages)  latest in thread

Message-ID: <452AE2FF.1020409@presinet.com>
Permalink:  ../452AE2FF.1020409@presinet.com/
Also on:    postgresql.org/message-id/452AE2FF.1020409@presinet.com

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: banderson@presinet.com, fourat@gmail.com, pgsql-novice@postgresql.org
  Subject: Re: Copying data from table to table (cloned tables)
  In-Reply-To: <452AE2FF.1020409@presinet.com>
  References: <621eda8a0610091651oc78994fy2b358260f5c9b58a@mail.gmail.com> <452AE2FF.1020409@presinet.com>

* 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