This is an old revision of the document!


By default, when you export data from postgres, it does not use a standard CSV format.

psql -U system_user -c "SELECT * FROM table_name" > exported_data.csv

To correct for the default format of the export, perform this on the exported data:

tail exported_data.csv | sed -e "s/ *|/|/g" -e "s/| */|/g" -e 's/^ *//' > input_file.csv

Then, you can import the data like this:

sudo -u system_user psql -d database -c "\copy table_name (specify columns) FROM 'input_file.csv'  (DELIMITER '|', FORMAT CSV, NULL '\N')"

sudo -u system_user psql -c "\copy table_name FROM STDIN (format csv, delimiter ',') " < import_data.csv