Skip site navigation (1) Skip section navigation (2)

Re: Copy data from table to table

From: Keith Worthington <KeithW(at)NarrowPathInc(dot)com>
To: PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Copy data from table to table
Date: 2005-04-28 03:20:51
Message-ID: 42705693.1030308@NarrowPathInc.com (view raw or flat)
Thread:
Lists: pgsql-novice
Frank Bax wrote:
> At 09:16 AM 4/27/05, Keith Worthington wrote:
> 
>> Hi All,
>>
>> I can not think of a way to copy data directly betweeen two tables.
>>
>> I can only think of two ways to copy the data indirectly.
>>
>> Method 1:  Write a function that loops through the results of a select 
>> query
>> running individual inserts for each record.
>>
>> Method 2:  Use SELECT INTO to put the desired data in a temporoary 
>> table; then
>> use COPY to store the data in a file and finally use COPY to read the 
>> data
>> from the file to the target table.
> 
> 
> 
> INSERT INTO ...  (SELECT FROM ...)
> 
> http://www.postgresql.org/docs/8.0/interactive/sql-insert.html
> 

Thank you all very much.  I had not run across this command yet.  I have 
run a few queries using it and it is going to work quite nicely for me.

-- 
Kind Regards,
Keith

In response to

pgsql-novice by date

Next:From: Richard LynchDate: 2005-04-28 03:50:44
Subject: Re: [PHP] temp tables
Previous:From: jeffwaltonDate: 2005-04-27 23:48:37
Subject: error: relation <tableName> does not exist

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group