[Postgres] Inserting Data Using the Copy Method
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.