Copying data from one table to another

Поиск
Список
Период
Сортировка
Искать

Copying data from one table to another

От:
Erwin 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

Re: Copying data from one table to another

От:
Richard Huxton <dev@archonet.com>
Дата:
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

Re: Copying data from one table to another

От:
Björn Lundin <bnl@tiscali.se>
Дата:
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

FAQ