Postgres COPY for CSV importing

Working on some integration between Geoserver, Django and NCGMP geodatabases, I often need to use PostgreSQL's COPY command to import data from CSV files into PostgreSQL. Here are some tips:

  1. You need to have the database table in place first. Django can be useful for that, depending on the situation.
  2. Create the CSV file with strings in double-quotes. Do not allow any null values, instead use a blank string, i.e. "".
  3. Do not include a header row with column names. However do make sure that columns are in the same order in the CSV as they are in the database table you're importing to.
  4. Copy command syntax looks like:
  5. su postgres
    psql -d {database name}
    copy {destination table name} from '{absolute path to csv file}' with csv;

    Don't forget the semicolon!