title: Postgres import a double quote value
body: <p>I have a large .csv file with 9 million rows. Some of these columns contain text with quotes or other special characters in them I would like to import from this .csv file into the database. For example I would like to import this row:</p>
  
  <pre><code>ID   BH   Units       Name                         Type_building      Year_cons
  1    4    900.00      schoolgebouw "De Bolster     Schoolgebouw       2014-01-01
  </code></pre>
  
  <p>As you can see there is a double quote in the fourth column. None of the values in the .csv file are quoted, but sometimes a double quote or backslash '\' appears in the text. When I try to upload the data using:</p>
  
  <pre><code>\COPY &lt;tablename&gt; FROM &lt;path to file&gt; WITH CSV DELIMITER ';' NULL '\N';
  </code></pre>
  
  <p>It gives an error message: ERROR value to long for type character varying(25).
  Apparently it sees the double quote as the start of a string and it tries to combine everything after it in the .csv file (including the fifth and sixth column) into a single cell (so that cell will contain 'De Bolster Schoolgebouw 2014-01-01'), which doesnt fit because the 'Name'  column allows max 25 characters.</p>
  
  <p>I found a similar topic (<a href="https://stackoverflow.com/questions/20402696/is-it-possible-to-turn-off-quote-processing-in-the-postgres-copy-command-with-cs">Is it possible to turn off quote processing in the Postgres COPY command with CSV format?</a>) in which this solution was presented:</p>
  
  <pre><code>\COPY &lt;tablename&gt; FROM &lt;path to file&gt; WITH CSV DELIMITER ';' QUOTE E'\b' NULL '\N';
  </code></pre>
  
  <p>I think what it does is sets the quote value (default is double quote) to something else, in this case a backspace, so it won't recognize a double quote as a quote anymore. However when I run this I get another error: INVALID input syntax for integer.</p>
  
  <p>What has happened is that every value now is quoted, so ID with value '1' becomes value '"1"' and because ID is defined as an integer it won't accept quotes.</p>
  
  <p>Do you have any idea how to import double quotes and other special characters from a .csv file into a postgres database?</p>
  
  <p>Thanks in advance!!</p>