Search Postgresql Archives

COPY FROM and NULL AS does not work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux