When importing a large data csv file into postgres, sometimes importing with csvkit alone will stall, and it's useful to use csvkit to build the table and the postgres COPY
command to get the rest of the data in there.
You will need to pip install csvkit
as well as psycopg2
, preferably in a virtualenv.
- First we'll make the
CREATE TABLE
statement and pipe it into a sql file. This example uses the first 100 lines of the file to determine the data type of each field, but this can be adjusted as needed.
csvfile.csv
= large data fileyourtable
= table you want to createoutputfile.sql
= file which will containCREATE TABLE
statement