Re: COPY for CSV documentation - Mailing list pgsql-patches

From Andrew Dunstan
Subject Re: COPY for CSV documentation
Date
Msg-id 3870.24.211.141.25.1081771632.squirrel@www.dunslane.net
Whole thread Raw
In response to Re: COPY for CSV documentation  (Bruno Wolff III <bruno@wolff.to>)
Responses Re: COPY for CSV documentation
List pgsql-patches
Bruno Wolff III said:
> On Mon, Apr 12, 2004 at 02:26:14 -0400,
>  Andrew Dunstan <andrew@dunslane.net> wrote:
>>
>> a few points:
>>
>> . in CSV mode, NULL should default to '' - that was in what I sent in.
>
> Postgres normally treats an empty string as an empty string. Are you
> sure you really want it to be treated as a NULL by default in this one
> place?
>

Yes ;-)

Otherwise, what will happen when we try to import into some non-text field
for which '' is not a valid value?

Spreadsheets commonly represent missing values as empty strings when
reading/writing CSVs - that's why this behaviour should be the default.

If you want to force it to use an empty string instead, simply specify
some unlikely value for NULL, like 'frobnitz'. But if you do, be prepared
for lots of errors unless you are importing into fields where empty string
is a valid text value.

Of course, a NOT NULL constraint will also break things, unless we went to
the MySQL method of handling insertion of NULL into a NOT NULL field ...
no I really am kidding.

cheers

andrew



pgsql-patches by date:

Previous
From: Fabien COELHO
Date:
Subject: Re: pg_restore ignore error patch
Next
From: Bruno Wolff III
Date:
Subject: Re: COPY for CSV documentation