Last active
July 19, 2021 08:10
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,val"ue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 | va"lue |
---|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TEMP TABLE IF NOT EXISTS csv( | |
id serial PRIMARY KEY, | |
value text | |
); | |
COPY csv FROM :FILE DELIMITER ',' CSV; | |
SELECT * FROM csv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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