Re: Conversion of columns during CSV Import

From: Edson Richter <edsonrichter(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Conversion of columns during CSV Import
Date: 2012-06-29 18:56:32
Message-ID: BLU0-SMTP473F312DA9D0E0BC1B564BACFE50@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Em 29/06/2012 14:10, Raymond O'Donnell escreveu:
> On 29/06/2012 08:54, Patrick Schneider wrote:
>> Hello,
>>
>> is there any possibility to convert special columns during an CSV import
>> via COPY?
>> For example:
>>
>> HELLO;WORLD;9999;011001
>>
>> 9999 should be converted to a character field
>> 011001 to the date 10th January 2001
>>
>> For the moment the only idea we have is, to import the CSV into a TEMP
>> table and
>> perform the conversion by a select from the temp to the target table.
> I don't think there is; AFAIK the only option is the one you've outlined.
>
> Ray.
>
>
On PostgreSQL 9.1, you can use File FDW to create a foreign table (that
is your CSV file).

Then you can use any kind of conversion allowed in the SELECT statement

There is an interesting article here:
http://www.postgresonline.com/journal/archives/250-File-FDW-Family-Part-1-file_fdw.html

Very easy to use.

Regards,

Edson

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andy Chambers 2012-06-29 19:16:21 Promotion of standby to master
Previous Message Alban Hertroys 2012-06-29 17:47:21 Re: Conversion of columns during CSV Import