Ignore quotation marks when importing a CSV file into PostgreSQL?
postgresql
Solution
Tab separated is the default format for copy statements. Treating them as CSV is just silly. (do you take this path just to skip the header ?)
copy articles from 'articles.tsv';
does exactly what you want.
Problem
I'm trying to import a tab-delimited file into my PostgreSQL database. One of the fields in my file is a "title" field, which occasionally contains actual quotation marks. For example, my tsv might look like: ``` id title 5 Hello/Bleah" Foo ``` (Yeah, there's just that one quotation mark in the title.) When I try importing the file into my database: ``` copy articles from 'articles.tsv' with delimiter E'\t' csv header; ``` I get this error, referencing that line: ``` ERROR: unterminated CSV quoted field ``` How do I fix this? Quotation marks are never used to surround entire fields in the file. I tried `copy articles from 'articles.tsv' with delimiter E'\t' escape E'\\' csv header;` but I get the same error on the same line.