Thread: Copying rows between tables?
I know I can select from one table into a new table, but is there a way to select from one table into an existing table (aside from copying everything to a file, editing the file and then copying from that file)? Without destroying existing entries, of course... I have an application where old records are archived into 'archive' tables. Occasionally there is a need to copy some of these old records into the 'active' table. Thanks for any pointers! Steve -- Steve Wampler -- swampler@noao.edu The gods that smiled on your birth are now laughing out loud.
----- Original Message ----- From: "Steve Wampler" <swampler@noao.edu> To: "Postgres-SQL" <pgsql-sql@postgresql.org> Sent: Tuesday, January 13, 2004 18:23 Subject: [SQL] Copying rows between tables? > > I know I can select from one table into a new table, but is > there a way to select from one table into an existing table > (aside from copying everything to a file, editing the file > and then copying from that file)? Without destroying existing > entries, of course... INSERT INTO table1(row1, row2) SELECT row1, row2 FROM archive_table; > > I have an application where old records are archived into > 'archive' tables. Occasionally there is a need to copy > some of these old records into the 'active' table. > > Thanks for any pointers! > Steve > -- > Steve Wampler -- swampler@noao.edu > The gods that smiled on your birth are now laughing out loud. > > ---------------------------(end of broadcast)--------------------------- > TIP 9: the planner will ignore your desire to choose an index scan if your > joining column's datatypes do not match
On Tue, Jan 13, 2004 at 09:23:48AM -0700, Steve Wampler wrote: > > I know I can select from one table into a new table, but is > there a way to select from one table into an existing table > (aside from copying everything to a file, editing the file > and then copying from that file)? Without destroying existing > entries, of course... insert into desttable (col1, col2, col3) select col1, col2, col3 from sourcetable where somecol = somevalue; -- __________________________________________________ "Nothing is as subjective as reality" Reinoud van Leeuwen reinoud.v@n.leeuwen.net http://www.xs4all.nl/~reinoud __________________________________________________
Dear Steve Wampler >I have an application where old records are archived into >'archive' tables. Occasionally there is a need to copy >some of these old records into the 'active' table. > > source_table(id: bigserial,uname: char,x1: char,x2: char,x3: char,x4: char) dest_table(id: bigserial,uname: char,x11: char,x21: char,x31: char,x41: char) you will do some thing like insert into dest_table(id,uname,x11,x21) (select id,uname,x1,x2 from source_table) Shootback if this helps Regards, Vishal Kashyap