COPY FROM and NULL AS does not work - Mailing list pgsql-general

From Arnaud Lesauvage
Subject COPY FROM and NULL AS does not work
Date
Msg-id 457003C7.3050708@freesurf.fr
Whole thread Raw
Responses Re: COPY FROM and NULL AS does not work  (Richard Huxton <dev@archonet.com>)
Re: COPY FROM and NULL AS does not work  (Dimitri Fontaine <dim@dalibo.com>)
List pgsql-general
HI List,

Trying to import data from a text file, with a semicolon as
  the delimiter, double-quotes as the quoting character.

I would like empty strings to be inserted as NULL values in
a varchar column. In the text file, they are writen as :
<some columns>;"";<some columns>

I tried
COPY table (columns) FROM textfile
DELIMITER AS ';' NULL AS '' CSV;
and
COPY table (columns) FROM textfile
DELIMITER AS ';' NULL AS '' CSV QUOTE AS '"';
but both commands insert empty strings where the text file's
data is "".

mydb=# CREATE TABLE tmptable
mydb-# (
mydb(#   one character varying,
mydb(#   two character varying
mydb(# )
mydb-# WITHOUT OIDS;
CREATE TABLE
mydb=#
mydb=# COPY tmptable (one, two)
mydb-# FROM 'E:\\Production\\Statistiques-Web\\temp.csv'
mydb-# DELIMITER AS ';' NULL AS '' CSV QUOTE AS '"';
COPY
mydb=#
mydb=# SELECT * FROM tmptable WHERE one = '';
  one | two
-----+-----
      |
      |
(2 rows)

mydb=# SELECT * FROM tmptable WHERE one IS NULL;
  one | two
-----+-----
(0 rows)

Content of the temp.csv file is :
"";""
"";""

What am I doing wrong ?
Thanks !

--
Arnaud

pgsql-general by date:

Previous
From: "Willy-Bas Loos"
Date:
Subject: Re: named cache
Next
From: Richard Huxton
Date:
Subject: Re: Restoring database from files on disk