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

Re: Copy data from table to table

From: George Weaver <gweaver(at)shaw(dot)ca>
To: KeithW(at)narrowpathinc(dot)com,PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Copy data from table to table
Date: 2005-04-27 13:36:00
Message-ID: 005501c54b2e$0fea0160$6400a8c0@Dell4500 (view raw or flat)
Thread:
Lists: pgsql-novice
Hi Keith,

Why not:

    INSERT INTO tablea SELECT * FROM tableb;

Or am I missing something about what you're trying to achieve?

Regards,
George


----- Original Message ----- 
From: "Keith Worthington" <keithw(at)narrowpathinc(dot)com>
To: "PostgreSQL Novice" <pgsql-novice(at)postgresql(dot)org>
Sent: Wednesday, April 27, 2005 8:16 AM
Subject: [NOVICE] Copy data from table to table


> 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.
>
> I have implemented the first method for situations where the source data 
> ends
> up in multiple tables but I want to check with all of you prior to 
> creating a
> function to do this for a single target table.
>
> As a curious point of information I worked with a database once that 
> allowed
> you to SELECT INTO an existing table.  It was handy.
>
> Kind Regards,
> Keith
>
> ---------------------------(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
> 



In response to

pgsql-novice by date

Next:From: Frank BaxDate: 2005-04-27 13:51:19
Subject: Re: Copy data from table to table
Previous:From: Michael FuhrDate: 2005-04-27 13:34:44
Subject: Re: Copy data from table to table

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