Re: [PATCHES] allow CSV quote in NULL

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Gregory Stark <stark(at)enterprisedb(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCHES] allow CSV quote in NULL
Date: 2007-07-27 16:03:19
Message-ID: 46AA1747.4030908@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches


[redirecting to -hackers]

Stephen Frost wrote:
> * Gregory Stark (stark(at)enterprisedb(dot)com) wrote:
>
>> "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
>>
>>
>>> Stephen Frost <sfrost(at)snowman(dot)net> writes:
>>>
>>>> Please find attached a minor patch to remove the constraints that a
>>>> user can't include the delimiter or quote characters in a 'NULL AS'
>>>> string when importing CSV files.
>>>>
>>> This can't really be sane can it?
>>>
>

Not very, no :-)
>
>> The alternative would be interpreting NULL strings after dequoting but that
>> would leave no way to include the NULL string literally. This solution means
>> there's no way to include it (if it needs quoting) but only when you specify
>> it this way.
>>
>
> Yeah, interpreting NULLs after dequoting means you've lost the
> information about if it's quoted or not, or you have to add some funky
> syntax to say "if it's quoted, do it differently...", which is no good,
> imv.
>
> What the patch does basically is say "give us the exact string that
> shows up between the unquoted delimiters that you want to be treated
> as a NULL." This removes the complexity of the question about quoting,
> unquoting, whatever, and makes it a very clear-cut, straight-forward
> solution with no impact on existing users, imv.
>
>
>

This looks too clever by half, to me. Someone facing the problem you are
facing would have to dig quite deep to find the solution you're promoting.

A much better way IMNSHO would be to add an extra FORCE switch. On
input, FORCE NOT NULL says to treat an unquoted null as the literal
value rather than as a null field for the columns named. The reverse
would be to tell it to treat a quoted null as null rather than as the
literal value, for the named columns. Perhaps that should just be "FORCE
NULL columnlist". It would be more explicit and at the same time would
only apply to the named columns, rather than discarding totally the
ability to distinguish between null and not null values.

This should probably be discussed on -hackers, anyway.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gregory Stark 2007-07-27 17:17:21 Re: [HACKERS] Document and/or remove unreachable code in tuptoaster.c from varvarlena patch
Previous Message Simon Riggs 2007-07-27 15:49:05 Re: stats_block_level

Browse pgsql-patches by date

  From Date Subject
Next Message Erwin Brandstetter 2007-07-27 16:17:19 Obsolete bits in docs for SQL-GRANT
Previous Message Gregory Stark 2007-07-27 15:36:22 Document and/or remove unreachable code in tuptoaster.c from varvarlena patch