Re: unused columns in copy

From: nha <lyondif02(at)free(dot)fr>
To: Chester C Young <chestercyoung(at)yahoo(dot)com>
Cc: Marcin Stępnicki <mstepnicki(at)gmail(dot)com>, PgSQL-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: unused columns in copy
Date: 2009-07-21 00:20:07
Message-ID: 4A6509B7.7010400@free.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

Le 21/07/09 0:59, Marcin Stępnicki a écrit :
> On Mon, Jul 20, 2009 at 3:22 PM, chester c young<chestercyoung(at)yahoo(dot)com> wrote:
>> is there a way for COPY FROM to ignore unused columns in CSV?
>>
>> in other words, if table t1 has columns c1, c2, and if csv has columns c1, c3, c2, could I do something like
>>
>> COPY t1( c1, null, c2 ) FROM 'file.csv'
>
> No, but you can use pgloader which can easily deal with your problem
> and much more. http://pgfoundry.org/projects/pgloader/
>

Depending on PostgreSQL version, copy restrictions may be performed (see
also documentation of PostgreSQL 8.4):
http://www.postgresql.org/docs/8.4/interactive/sql-copy.html

Assuming that a CSV file contains data with column headers c1, c2, and
c3, the following statement would retrieve only columns c1 and c2 from
this file to a table t1:
COPY t1(c1, c2) FROM '/path/to/file.csv';

Regards.
--
nha / Lyon / France.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message nha 2009-07-21 11:14:36 Re: Storing/sorting hex data in PostgreSQL
Previous Message nha 2009-07-21 00:07:03 Re: how to tell if column set on update