Re: Fwd: Copy out wording

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fwd: Copy out wording
Date: 2009-09-03 11:22:37
Message-ID: 9837222c0909030422t68352befqb6203ab9fcdf7815@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-hackers pgsql-hackers

On Thu, Sep 3, 2009 at 13:19, Andrew Dunstan<andrew(at)dunslane(dot)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 Hagander
Me: http://www.hagander.net/
Work: http://www.redpill-linpro.com/

In response to

Responses

Browse pgadmin-hackers by date

  From Date Subject
Next Message Dave Page 2009-09-03 11:31:36 Re: New minor release?
Previous Message Guillaume Lelarge 2009-09-03 11:20:32 New minor release?

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2009-09-03 11:31:40 Re: Fwd: Copy out wording
Previous Message Andrew Dunstan 2009-09-03 11:19:07 Re: Fwd: Copy out wording