Skip to content

Instantly share code, notes, and snippets.

@andrewp-as-is
Last active July 19, 2021 08:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewp-as-is/bca0bbca337f44461a040a90590925ab to your computer and use it in GitHub Desktop.
Save andrewp-as-is/bca0bbca337f44461a040a90590925ab to your computer and use it in GitHub Desktop.
postgres cvs ERROR: unterminated CSV quoted field
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 1.
1,val"ue
CREATE TEMP TABLE IF NOT EXISTS csv(
id serial PRIMARY KEY,
value text
);
COPY csv FROM :FILE DELIMITER ',' CSV;
SELECT * FROM csv;
#!/usr/bin/env bash
db="tmp_$(openssl rand -hex 6)"
createdb "$db"
psql -v "FILE='$PWD/_invalid.csv'" -f import.sql "$db"
psql -v "FILE='$PWD/_valid.csv'" -f import.sql "$db"
dropdb "$db"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment