[Postgres] Inserting Data Using the Copy Method

Heitor Helmer Herzog
1 min readFeb 4, 2018

--

Sometimes you need to input a lot of data quickly and a more efficient way of doing this is using the postgres copy.

First we create a copy of the table on disk C so we can take the test.

The postgres creates a cvs file of the separated table by semicolon.

copy (SELECT * FROM table) TO ‘C: \ directory \ table.csv’ DELIMITER ‘;’ CSV HEADER;

We deleted the table
TRUNCATE table table;
And we copied the created cvs to the table again
COPY table FROM ‘’ C: \ directory \ table.csv ‘DELIMITER’; ‘ CSV HEADER;

With this we copied in a few minutes or seconds depending on the size of the various table records. Much faster than using insert.

--

--

Heitor Helmer Herzog
Heitor Helmer Herzog

Written by Heitor Helmer Herzog

Software developer, In love with games and the industry. Let’s code! About me: www.linkedin.com/in/heitorhherzog

No responses yet