Re: Fwd: Copy out wording - Mailing list pgsql-hackers

From Magnus Hagander
Subject Re: Fwd: Copy out wording
Date
Msg-id 9837222c0909030422t68352befqb6203ab9fcdf7815@mail.gmail.com
Whole thread Raw
In response to Re: Fwd: Copy out wording  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: Fwd: Copy out wording
List pgsql-hackers
On Thu, Sep 3, 2009 at 13:19, Andrew Dunstan<andrew@dunslane.net> wrote:
>
>
> Magnus Hagander wrote:
>>
>> Our documentation for COPY
>> (http://www.postgresql.org/docs/8.4/static/sql-copy.html) has the
>> following to say:
>> "
>>  The CSV format has no standard way to distinguish a NULL value from
>> an empty string. PostgreSQL's COPY handles this by quoting. A NULL is
>> output as the NULL string and is not quoted, while a data value
>> matching the NULL string is quoted. Therefore, using the default
>> settings, a NULL is written as an unquoted empty string, while an
>> empty string is written with double quotes (""). Reading values
>> follows similar rules. You can use FORCE NOT NULL to prevent NULL
>> input comparisons for specific columns.
>> "
>>
>> Shouldn't that be:
>> "A NULL is output as the NULL string and is not quoted, while a data
>> value matching the empty string is quoted"?
>>
>> If not, then what really is the difference between a NULL and a NULL
>> string?
>>
>>
>
>
> No, it shouldn't. Let's say NULL is represented as "foo". Then a null
> between delimiters will be written as
>
>   delimiter foo delimiter
>
> while the string "foo" will be
>
>   delimiter quotechar foo quotechar delimiter
>
> and an empty non-null string will be
>
>   delimiter delimiter
>
> unless you have FORCE QUOTE on for it, in which case it will be
>
>   delimiter quotechar quotechar delimiter
>
>
> We had quite a bit of debate on the shape of CSV output at the time it was
> done (during 8.0), and that's what we came up with. It has the useful
> property that we can round-trip the data, i.e. we can read back the data we
> output without losing information about nulls, no matter what the NULL
> string is, something we have always been resistant to changing.
>
> If you think we could explain it better, by all means have a go at it. But
> your proposed change isn't accurate. Here is an illustration of the above:

Oh, hang on, "the NULL string" refers to the copy parameter? Not a
part of the data? I read it as "a string being NULL". Maybe something
like "the value of the NULL string parameter" to be overly clear for
people like me? :-)

(FWIW, I totally agree with the feature, I was just confused by the docs)

-- Magnus HaganderMe: http://www.hagander.net/Work: http://www.redpill-linpro.com/


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Fwd: Copy out wording
Next
From: Andrew Dunstan
Date:
Subject: Re: Fwd: Copy out wording