Re: data loading

From: Jeff Eckermann <jeff_eckermann(at)yahoo(dot)com>
To: azwa(at)nc(dot)com(dot)my, pgsql-sql(at)postgresql(dot)org
Subject: Re: data loading
Date: 2004-01-10 18:28:38
Message-ID: 20040110182838.44707.qmail@web20804.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


--- Richard Huxton <dev(at)archonet(dot)com> wrote:
> On Friday 09 January 2004 02:13, azwa(at)nc(dot)com(dot)my
> wrote:
> > Hi,
> >
> >
> > i try to load data from flat file (comma
> delimiter format) into
> > temporary table . i use COPY command as below:
> >
> > dwnc=# copy biosadm.custdo_temp
> > dwnc-# from
> '/home/bios/customer_data/CustomerDO_new.CSV'
> > dwnc-# WITH DELIMITER ',' ;
> >
> > ERROR: copy: line 141, Extra data after last
> expected column
>
> Does line 141 (or nearby) have a comma somewhere in
> its data? That would fool
> the COPY into mis-counting the columns. See the COPY
> entry in the SQL Command
> Reference chapter of the manuals - you'll want to
> escape any commas with a
> backslash:
> \,

CSV deals with embedded commas by quoting the data
field that contains it. Applications that are aware
of this will know to ignore commas within quoted
strings. COPY is not smart enough to figure this out
(nor smart enough to strip off any quotes, which will
be imported as data). If you know for a fact that
your data contains no quotes, then you can get away
with the "with delimiters ','" trick. Otherwise, you
will need to preprocess your data through something
that will parse the CSV format, e.g. some Perl module.
Note that hand rolled solutions usually underestimate
the complexity of dealing with CSV data, and why
bother when others have already solved the problem for you.

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Greg Sabino Mullane 2004-01-11 19:17:26 Re: Different query results in psql and Perl DBI with Postgres 7.2.1
Previous Message Tom Lane 2004-01-10 16:48:45 Re: Adding a column to a VIEW which has dependent objects.