Re: Review: Patch FORCE_NULL option for copy COPY in CSV mode

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Ian Lawrence Barwick <barwick(at)gmail(dot)com>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, Payal Singh <payal(at)omniti(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Review: Patch FORCE_NULL option for copy COPY in CSV mode
Date: 2014-03-05 14:58:47
Message-ID: CAB7nPqS=dbePrb-NiDfE+JZGB6WXLksrwDoFuRkHtjEn0tXYTQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Mar 5, 2014 at 11:37 PM, Ian Lawrence Barwick <barwick(at)gmail(dot)com> wrote:
> 2014-03-05 23:27 GMT+09:00 Andrew Dunstan <andrew(at)dunslane(dot)net>:
>>
>> On 03/05/2014 09:11 AM, Michael Paquier wrote:
>>>
>>> After testing this feature, I noticed that FORCE_NULL and
>>> FORCE_NOT_NULL can both be specified with COPY on the same column.
>>> This does not seem correct. The attached patch adds some more error
>>> handling, and a regression test case for that.
>>>
>>
>>
>> Strictly they are not actually contradictory, since FORCE NULL relates to
>> quoted null strings and FORCE NOT NULL relates to unquoted null strings.
>> Arguably the docs are slightly loose on this point. Still, applying both
>> FORCE NULL and FORCE NOT NULL to the same column would be rather perverse,
>> since it would result in a quoted null string becoming null and an unquoted
>> null string becoming not null.
>
> Too frazzled to recall clearly right now, but I think that was the somewhat
> counterintuitive conclusion I originally came to.
In this case I may be an intuitive guy :), but OK I see your point. So
if we specify both this produces the exact opposite as the default,
default being an empty string inserted for a quoted empty string and
NULL inserted for a non-quoted empty string. So yes I'm fine with a
note on the docs about that, and some more regression tests.

Btw, if we allow this behavior in COPY, why doesn't file_fdw allow
both options to be allowed on the same column for a foreign table?
Current behavior of file_fdw seems rather inconsistent with COPY as it
stands now.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2014-03-05 15:03:33 Re: Review: Patch FORCE_NULL option for copy COPY in CSV mode
Previous Message Andrew Dunstan 2014-03-05 14:53:41 Re: jsonb and nested hstore