Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Latest commit

 

History

History
23 lines (13 loc) · 1.31 KB

01-bulk-insert-and-export-files.md

File metadata and controls

23 lines (13 loc) · 1.31 KB

This is the format when using Postgres:

  postgres=# copy <table name> <column names> from '<full file path to CSV file>' DELIMITER ',' CSV HEADER; 

Bult Insert Image

This comand will bulk insert all rows from the file into the table.

SQL Bulk Import Gif

The copy command makes this possible. Defining columns is optional, and renames the columns from the original file. If left out, HEADER will be pulled in from the imported file.

In this case, the DELIMITER defaults to tabs, but with CSV we need to choose commas (this works like a key value pair).

And CSV and HEADER are two separate options: CSV for the file type, HEADER tells the copy command that the first row in the file contains headers and shouldn't be copied into the DB.

If you change "from" to "to" you can export a copy of data to the file FROM the DB as a CSV.

Bulk Insert Reverse Image