Re: unused columns in copy - Mailing list pgsql-sql

From nha
Subject Re: unused columns in copy
Date
Msg-id 4A6509B7.7010400@free.fr
Whole thread Raw
In response to Re: unused columns in copy  (Marcin Stępnicki <mstepnicki@gmail.com>)
List 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@yahoo.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.


pgsql-sql by date:

Previous
From: nha
Date:
Subject: Re: how to tell if column set on update
Next
From: JJ
Date:
Subject: Storing/sorting hex data in PostgreSQL