pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
unused columns in copy
3+ messages / 3 participants
[nested] [flat]

* unused columns in copy
@ 2009-07-20 13:22  chester c young <chestercyoung@yahoo.com>
  0 siblings, 1 reply; 3+ messages in thread

From: chester c young @ 2009-07-20 13:22 UTC (permalink / raw)
  To: pgsql-sql


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'


      



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: unused columns in copy
@ 2009-07-20 22:59  Marcin Stępnicki <mstepnicki@gmail.com>
  parent: chester c young <chestercyoung@yahoo.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Marcin Stępnicki @ 2009-07-20 22:59 UTC (permalink / raw)
  To: chester c young <chestercyoung@yahoo.com>; +Cc: pgsql-sql

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/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: unused columns in copy
@ 2009-07-21 00:20  nha <lyondif02@free.fr>
  parent: Marcin Stępnicki <mstepnicki@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: nha @ 2009-07-21 00:20 UTC (permalink / raw)
  To: Chester C Young <chestercyoung@yahoo.com>; +Cc: Marcin Stępnicki <mstepnicki@gmail.com>; 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.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2009-07-21 00:20 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-07-20 13:22 unused columns in copy chester c young <chestercyoung@yahoo.com>
2009-07-20 22:59 ` Marcin Stępnicki <mstepnicki@gmail.com>
2009-07-21 00:20   ` nha <lyondif02@free.fr>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox