Re: import csv file into table

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Jude DaShiell <jdashiel(at)panix(dot)com>
Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: import csv file into table
Date: 2015-06-13 13:24:55
Message-ID: CAKFQuwa5wDyFKVE4tYdNxaJu9atbsUhssJf2MKydgX=0BJSn+w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

If the field separator is <single-quote comma single-quote> then the first
and last single-quotes complete the first and last field quotes
Respectively and should not be removed. You simply need to specify <comma>
as your field separator and single-quote and your quote symbol. The
documentation for copy explains how you do this.

David J.

On Saturday, June 13, 2015, Jude DaShiell <jdashiel(at)panix(dot)com> wrote:

> I can remove the single quotes from beginning and ends of all records
> easily. Do the single quotes need to be removed from around all fields or
> just from the beginnings and ends of records? I have no comas inside of
> fields in the file. The file first came from emacs-orgmode then was edited
> to create the csv file.
> Thanks much for help on this problem and thanks for the link to the
> pgloader package I'll check that out shortly.
>
> On Fri, 12 Jun 2015, David G. Johnston wrote:
>
> Date: Fri, 12 Jun 2015 12:52:17
>> From: David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
>> To: Jude DaShiell <jdashiel(at)panix(dot)com>
>> Cc: "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
>> Subject: Re: [NOVICE] import csv file into table
>>
>> On Fri, Jun 12, 2015 at 11:38 AM, Jude DaShiell <jdashiel(at)panix(dot)com>
>> wrote:
>>
>> ?[...]
>>> and ' for beginning and end of records
>>> ?[...]
>>>
>>>
>> ?This is the problem. You need to remove the first and last single-quote
>> and ensure that fields do not contain embedded commas. COPY will work if
>> those two things hold true. Embedded commas and field quoting are the
>> main
>> difficulties with using comma-separated format.?
>>
>> COPY is efficient but it expects you to provide clean data to it. You
>> need
>> to fix those items externally to PostgreSQL.
>>
>> I have not used it myself but you might evaluate pgloader.
>> http://pgloader.io/
>>
>> David J.
>>
>>
> --
>
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Wood 2015-06-13 13:55:42 Re: import csv file into table
Previous Message Jude DaShiell 2015-06-13 11:00:06 Re: import csv file into table