Re: COPY formatting

From: "Thomas Swan" <tswan(at)idigx(dot)com>
To: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
Cc: "Postgresql Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: COPY formatting
Date: 2004-03-19 18:43:43
Message-ID: 57217.199.222.14.2.1079721823.squirrel@www.idigx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

<quote who="Andrew Dunstan">
>
>
> Karel Zak wrote:
>
>> The problem with CSV is that it will correctly work with new protocol
>> only. Because old versions of clients are newline sensitive. And CSV
>> can contains newline in by quotation marks defined attributes:
>>
>> "John", "Smith", "The White House
>> 1600 Pennsylvania Avenue NW
>> Washington, DC 20500", "male", "open source software office"
>>
>> It is one record.
>>
>
> (Long Live President Smith!)
>
> I have never seen such a beast, and if I had been asked off the cuff
> would have said that it was probably illegal, except that I know of no
> standard actually defining the format. Perhaps others (Joshua Drake or
> Josh Berkus?) have wider experience. I think in any case we should
> ignore those for now and handle the straightforward case.
>
> I *have* seen monstrosities like fields that do not begin with the quote
> character but then break into a quote, e.g.:
>
> 1,2,a,123"abc""def",6,7,8
>

I have dealt with both, frequently. The CSV format allows you to begin a
block of text with the quote. Newlines are included in that quoted space.
If qoutes are included in the field then the quotes are double quotes to
denote they are not part of the quoted space.

Also, the following is valid.

1,2,,,"",,,""

"" is empty.

1,2,3,"""",,,,"",

The 4 quotes denote a single double quote.

Writing simple CSV converts that just explode on commas and newlines miss
these oddities.

Try exporting an Access table with a Memo field (containg multiple lines)
to CSV.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2004-03-19 18:59:54 Re: COPY formatting
Previous Message Tom Lane 2004-03-19 17:57:46 Syntax error reporting (was Re: [PATCHES] syntax error position "CREATE FUNCTION" bug fix)