Re: [NOVICE] COPY from temp table to main table insted of INSERT INTO

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: [NOVICE] COPY from temp table to main table insted of INSERT INTO
Дата
Msg-id CAKFQuwaRgXW4CoJ9Hi-A14+O-utGQ26nTNs3SXQeai0bD_oUrg@mail.gmail.com
обсуждение исходный текст
Ответ на [NOVICE] COPY from temp table to main table insted of INSERT INTO  (Stephen Froehlich <s.froehlich@cablelabs.com>)
Ответы Re: [NOVICE] COPY from temp table to main table insted of INSERT INTO
Список pgsql-novice
On Tue, Jul 11, 2017 at 9:45 AM, Stephen Froehlich <s.froehlich@cablelabs.com> wrote:

I tend to do mass inserts to my database, but INSERT INTO is taking quite a while for 100k values.

 

What is the syntax for using the COPY command to copy a well formatted temp table to the “end” of the primary table?  I am having trouble understanding https://www.postgresql.org/docs/9.5/static/sql-copy.html.



​Tables don't have beginnings or ends.

Are you intending to use client software to access the source data or are you planning on putting the source data in a location where the server o/s user can see it?​

If you already have an actual temporary table inside the database you wouldn't use COPY.  COPY is intended to transfer data from/to an external file (including stdin/stdout).

Generally:

(in psql)
BEGIN;
CREATE TEMP TABLE tmptbl ( cols );
\copy tmptbl from '/tmp/file-to-load.csv' with ( ... )
INSERT INTO tbl SELECT * FROM tmptbl;
COMMIT;

\copy in psql constructs an appropriate "COPY" SQL command, executes it on the server, and then funnels the contents of "file" to the server.

David J.

В списке pgsql-novice по дате отправления:

Предыдущее
От: Stephen Froehlich
Дата:
Сообщение: [NOVICE] COPY from temp table to main table insted of INSERT INTO
Следующее
От: Stephen Froehlich
Дата:
Сообщение: Re: [NOVICE] COPY from temp table to main table insted of INSERT INTO