title: CSV import via COPY FROM won't work with NULL values contained
body: <p>I've a CSV file and want to import this via the Postgres command "COPY x FROM y" in my  database. This database has two columns: a column called "id" (serial, NULL not allowed) and a "value" column (varchar, NULL is allowed and a constraint is applied). I'll provide the short create script for the test database below.
  The CSV is obtained by exporting it from an OpenOffice spreadsheet. The CSV content is also provided at the end.</p>
  
  <p><strong>My problem:</strong></p>
  
  <p>When executing the following command ...</p>
  
  <pre><code>COPY mytable FROM '/tmp/testdata.csv' CSV HEADER NULL AS E'\N';
  </code></pre>
  
  <p>... I'm getting this error message:</p>
  
  <pre><code>ERROR:  value for domain car_manufacturer violates check constraint "car_manufacturer_format"
  CONTEXT:  COPY mytable, line 3, column value: "\N"
  
  ********** Error **********
  
  ERROR: value for domain car_manufacturer violates check constraint "car_manufacturer_format"
  SQL state: 23514
  Context: COPY mytable, line 3, column value: "\N"
  </code></pre>
  
  <p>Here is the content of the <strong>CSV</strong> file (exported directly from OpenOffice, so it should conform to the standards):</p>
  
  <pre><code>"ID","value"
  1,"Mercedes"
  2,"\N"
  </code></pre>
  
  <p>Obviously, Postgres has some problems in understanding that the "\N" in my CSV file is meant to be a NULL value (which is actually allowed in this column). First, it is checking the whole string "\N" against the constraint. As it does not conform to the RegexPattern defined in the constraint, it will provide the error mentioned above. I tried several modifications of my COPY-FROM-Command but none of these led to a successful import.</p>
  
  <p><strong>In short:</strong> I need a solution for allowing Postgres me to import a csv via the copy-from-command and, moreover, being allowed to have "\N"-entries in string/varchar columns representing NULL-values.</p>
  
  <p>I really need to do it with the Copy command because I want to automate the import process by using a script. When using phpPGAdmin for importing the CSV everything works fine. This is due to the fact, that phpPgAdmin is sending INSERT-Commands to the postgres server. So it is obviously not using the "copy from"-command...</p>
  
  <p><strong>Additional info:</strong></p>
  
  <p>Here is the <strong>create script</strong> for the database:</p>
  
  <pre><code>CREATE DOMAIN car_manufacturer AS VARCHAR (100) CONSTRAINT car_manufacturer_format CHECK
  (VALUE SIMILAR TO '[A-Z][A-Za-z]+|');
  COMMENT ON DOMAIN car_manufacturer IS 'The name of a car manufacturer (e.g, Ford, BMW, Chrysler, Mercedes etc.)';
  
  CREATE TABLE mytable
  (
    "ID" serial NOT NULL,
    "value" car_manufacturer,
    CONSTRAINT pk_mytable PRIMARY KEY ("ID")
  )
  WITH (
    OIDS=FALSE
  );
  ALTER TABLE mytable OWNER TO postgres;
  </code></pre>
  
  <p>Thanks a lot in advance!</p>
  
  <p>Cheers,
  Philipp</p>
  
  <p>PS: My example is boiled down in order to show you the actual problem. So, please, don't be bothered by the triviality of this example :-)</p>