From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
---|---|
To: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
Cc: | Ian Lawrence Barwick <barwick(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Patch: FORCE_NULL option for copy COPY in CSV mode |
Date: | 2013-10-07 19:06:42 |
Message-ID: | CA+TgmobWtajy_TJz5XDQ-XJy0QKoXgTcws3W5_g2sEC3bOHhMg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Sat, Oct 5, 2013 at 7:38 AM, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> wrote:
> On Sun, Sep 29, 2013 at 1:39 PM, Ian Lawrence Barwick <barwick(at)gmail(dot)com> wrote:
>> Hi,
>>
>> This patch implements the following TODO item:
>>
>> Allow COPY in CSV mode to control whether a quoted zero-length
>> string is treated as NULL
>>
>> Currently this is always treated as a zero-length string,
>> which generates an error when loading into an integer column
>>
>> Re: [PATCHES] allow CSV quote in NULL
>> http://archives.postgresql.org/pgsql-hackers/2007-07/msg00905.php
>>
>>
>> http://wiki.postgresql.org/wiki/Todo#COPY
>>
>>
>> I had a very definite use-case for this functionality recently while importing
>> CSV files generated by Oracle, and was somewhat frustrated by the existence
>> of a FORCE_NOT_NULL option for specific columns, but not one for
>> FORCE_NULL.
>
> While going through documentation of this patch to understand it's
> usage, I found a small mistake.
>
> + Force the specified columns' values to be converted to <literal>NULL</>
> + if the value contains an empty string.
>
> It seems quote after columns is wrong.
That's a correct plural possessive in English, but in might be better
worded as "Force any empty string encountered in the input for the
specified columns to be interpreted as a NULL value."
> Also if your use case is to treat empty strings as NULL (as per above
> documentation), can't it be handled with "WITH NULL AS" option.
> For example, something like:
>
> postgres=# COPY testnull FROM stdin with CSV NULL AS E'';
> Enter data to be copied followed by a newline.
> End with a backslash and a period on a line by itself.
>>> 50,
>>> \.
> postgres=# select * from testnull;
> a | b
> ----+------
> 50 | NULL
> (1 row)
Good point. If this patch is just implementing something that can
already be done with another syntax, we don't need it.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
From | Date | Subject | |
---|---|---|---|
Next Message | Andrew Dunstan | 2013-10-07 19:25:14 | Re: Patch: FORCE_NULL option for copy COPY in CSV mode |
Previous Message | Robert Haas | 2013-10-07 19:02:36 | Re: mvcc catalo gsnapshots and TopTransactionContext |