Importing (and exporting) a postgre table

Importing a CSV into a postgres table is relatively easy:

From the postgres command line:

\copy table (field1,field2) FROM filename DELIMITER ',' QUOTE '"' CSV

If the csv fields match the table fields:

\copy table FROM filename DELIMITER ',' QUOTE '"' CSV

So, to export, you run the following:

\copy table TO filename DELIMITER ',' QUOTE '"' CSV

For both importing and exporting you can leave the DELIMITER and QUOTE off….the default DELIMITER is tab