pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Terry Fielder <terry@greatgulfhomes.com>
To: pgsql-sql@postgresql.org
Subject: SQL copy from csv with explicit field ordering
Date: Thu, 01 Mar 2001 15:46:06 -0500
Message-ID: <3A9EB50E.C2770BEA@greatgulfhomes.com> (raw)

I guess this is really a SQL question:

I have a csv that I want to import, but the csv has different column
ordering.

I have tried putting the column names in the first row, but then the
copy command fails on field which is data type (eg it is seeing the
cells in first row as data, not header info).

ggtest=> copy ap_trans from '/var/dbase/ap_trans.csv' using delimiters
',';
ERROR:  pg_atoi: error in "id": can't parse "id"


The help indicates:
ggtest=> \h copy
Command: copy
Description: copy data to and from a table
Syntax:
        COPY [BINARY] class_name [WITH OIDS]
        TO|FROM filename|STDIN|STDOUT [USING DELIMITERS 'delim'];


I have tried WITH OIDS but with same results.

Is there somewhere that I can either enable the first line of CSV as
header names

OR

Can I explicitly define my import field ordering from within the select
statement?

Thanks

Terry Fielder
terry@greatgulfhomes.com




view thread (2+ messages)  latest in thread

Message-ID: <3A9EB50E.C2770BEA@greatgulfhomes.com>
Permalink:  ../3A9EB50E.C2770BEA@greatgulfhomes.com/
Also on:    postgresql.org/message-id/3A9EB50E.C2770BEA@greatgulfhomes.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: terry@greatgulfhomes.com
  Subject: Re: SQL copy from csv with explicit field ordering
  In-Reply-To: <3A9EB50E.C2770BEA@greatgulfhomes.com>
  References: <3A9EB50E.C2770BEA@greatgulfhomes.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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