[Postgres] Inserting Data Using the Copy Method

Heitor Helmer Herzog
1 min readApr 10, 2017

--

Sometimes it is necessary to insert 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

Now We delete 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 copy in a few minutes or seconds depending on the size of the various table
Records. Much faster than using the 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