title: Importing CSV with commas in string values
body: <p>I am trying to import a trivial CSV to Postgres 8.4 database:</p>
  <p>Here is a table:</p>
  <pre><code>CREATE TABLE public.sample (
    a VARCHAR, 
    b VARCHAR
  ) WITHOUT OIDS;
  </code></pre>
  <p>Here is a CSV file sample:</p>
  <pre><code>&quot;foo&quot;,&quot;bar, baz&quot;
  </code></pre>
  <p>The query:</p>
  <pre><code>COPY sample FROM '/tmp/sample.csv' USING DELIMITERS ',';
  </code></pre>
  <p>Throws an exception:</p>
  <pre><code>ERROR:  extra data after last expected column
  CONTEXT:  COPY sample, line 1: &quot;&quot;foo&quot;,&quot;bar, baz&quot;&quot;
  </code></pre>
  <p>But, well, CSV parsing is not rocket science and I wonder if it is not possible to solve without reformatting the source CSV file.</p>
  <p>Input comes from a 3rd party, I cannot change the format.<br />
  (I understand I could pre-process to change the delimiter before I import it.)</p>
  <p><strong>Final solution</strong>:</p>
  <pre><code>COPY sample FROM '/tmp/sample.csv' WITH DELIMITER ',' CSV;
  </code></pre>
  <p>Originally taken from <a href="https://stackoverflow.com/a/9682174/251311">https://stackoverflow.com/a/9682174/251311</a>, and documentation page is <a href="http://www.postgresql.org/docs/8.4/static/sql-copy.html" rel="nofollow noreferrer">http://www.postgresql.org/docs/8.4/static/sql-copy.html</a></p>