PostgreSQL - Import CSV file to a table
How to Import CSV file to a table in PostgreSQL?
1. Using SQL command
You can run this command to import CSV file:
COPY table_name FROM '/path_to_csv_file.csv' WITH FORMAT csv;
or
COPY table_name FROM '/path_to_csv_file.csv' DELIMITERS ',' CSV;
Keep in mind that you have to keep the column names on the csv file the same as columns of the table.
2. Using TablePlus
In TablePlus, you can import csv via the GUI.
To import a CSV file to a current table:
- Choose
File > Import > From CSV...
from the menu bar - Right-click on the table in the left sidebar or right-click in the data content and choose
Import CSV
After importing, press Command + R
to reload current workspace and see newly imported data.
Need a good GUI tool for PostgreSQL? Check out TablePlus. It’s native, beautiful, and available for free.
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS.