Re: \copy ... with null as '' csv doesn't get nulls

Поиск
Список
Период
Сортировка
Искать
От
Lew
Тема
Re: \copy ... with null as '' csv doesn't get nulls
Дата
Msg-id
jLidnei9qO3kINTanZ2dnUVZ_tmhnZ2d@comcast.com
Ответ на
Список
Дерево обсуждения
\copy ... with null as '' csv doesn't get nulls Ivan Sergio Borgonovo <mail@webthatworks.it>
Re: \copy ... with null as '' csv doesn't get nulls Lew <lew@lwsc.ehost-services.com>
Re: \copy ... with null as '' csv doesn't get nulls Ivan Sergio Borgonovo <mail@webthatworks.it>
Re: \copy ... with null as '' csv doesn't get nulls Lew <lew@lwsc.ehost-services.com>
Re: \copy ... with null as '' csv doesn't get nulls Ivan Sergio Borgonovo <mail@webthatworks.it>
Re: \copy ... with null as '' csv doesn't get nulls Adrian Klaver <aklaver@comcast.net>
Ivan Sergio Borgonovo wrote:
> I'd expect this:
> 
> \copy tablename from 'filename.csv' WITH NULL as '' CSV HEADER
> 
> whould import "" as NULL.
> 
> The input file is UTF-8 (not Unicode/UTF-16).
> I checked the hexdump and the "wannabe" NULL are actually
> 2c 22 22 2c -> ,"",
> 
> all fields are varchar that admit NULL
> 
> but still I get empty strings ('') in spite of NULL.
> 
> Am I missing something or it is a well known "feature"?

I went to the docs for COPY and they say,
> The default is \N (backslash-N) in text mode, and a empty value with no quotes in CSV mode.

That "with no quotes" phrase caught my attention.

Try eliminating the double quotes in the CSV file.  "Wannabe" NULL would then be
   ,, (consecutive commas)
in the CSV.  From the docs, you don't even need the "NULL AS" clause in your 
COPY statement.

-- 
Lew
В списке pgsql-general по дате отправления
От: Lew
Дата:
От: Lew
Дата:
FAQ