Copying data from one table to another

Started by Erwin Van de Veldeabout 22 years ago3 messagesgeneral
Jump to latest
#1Erwin Van de Velde
erwin.vandevelde@ua.ac.be

Hi,

I have to copy data from one table to another, and I was wondering if there is
an easier way to do that than to have a lot of inserts one after another. I
already looked at the copy command, but what I need should happen in my
program itself, while the user is waiting, and it's only a partial copy of
the first table to the second (which has it's own fields, although with
default values to start with). So the copy command didn't seem an easy (or
fast) way to do that. Is there a trick to let the INSERT command take more
than one tuple at once?

Thanks in advance,
Erwin Van de Velde
Student of University of Antwerp,
Belgium

#2Björn Lundin
bnl@tiscali.se
In reply to: Erwin Van de Velde (#1)
Re: Copying data from one table to another

Erwin Van de Velde wrote:

Hi,

I have to copy data from one table to another, and I was wondering if
there is an easier way to do that than to have a lot of inserts one after
another.

insert into target_table select * from source-table where ...;

Bj�rn Lundin

#3Richard Huxton
dev@archonet.com
In reply to: Erwin Van de Velde (#1)
Re: Copying data from one table to another

On Saturday 28 February 2004 16:08, Erwin Van de Velde wrote:

I have to copy data from one table to another, and I was wondering if there
is an easier way to do that than to have a lot of inserts one after
another.

Is there a trick to let the INSERT
command take more than one tuple at once?

Think in sets. As long as you can define the conditions for copying rows:

INSERT INTO table2 SELECT * FROM table1 WHERE somefield='some value';

--
Richard Huxton
Archonet Ltd