Re: Error Importing CSV File

From: Rick Genter <rick(dot)genter(at)gmail(dot)com>
To: rick(dot)genter(at)gmail(dot)com
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Error Importing CSV File
Date: 2011-07-15 17:19:23
Message-ID: CADie1rya7bs_7UxsH3Q6rOpXF0Zq8kJEXersXdr1vPPVG090pQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I think the COPY is expecting the first line of the file to be a header and
it doesn't find a column named "96799" in the table. Try putting a line at
the top of the file that looks like this:

zip_code,latitude,longitude,city,state,county

On Fri, Jul 15, 2011 at 10:10 AM, Susan Cassidy <scassidy(at)edgewave(dot)com>wrote:

> There seems to be no reason it should be looking for an integer, if your
> table definition as shown is correct. You don't have any integers listed.
>
> Also, why does it think that the column id is 96799?
>
> Stupid question, but are you logged into the right database? Maybe a
> different db has a different table definition for that table name?
>
> Maybe it is using a different file than you think it is? I had to specify
> the full path to get the COPY to work on my test database.
>
> When I created the same table as you specified, and created a test CSV
> file, it worked fine both with and without quotes.
>
> Susan
>
> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org [mailto:
> pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Bryan Nelson
> Sent: Friday, July 15, 2011 9:04 AM
> To: pgsql-general(at)postgresql(dot)org
> Subject: [GENERAL] Error Importing CSV File
>
> I am having problems importing a CSV file of sample data for testing
> in a web app.
>
> Columns & Types
> -------------------
> zip_code - text
> lattitude - float8
> longitude - float8
> city - text
> state - text
> county - text
>
> Some Sample Data From CSV File
> ------------------------------
> 96799,-7.209975,-170.7716,PAGO PAGO,AS,AMERICAN SAMOA
> 96941,7.138297,151.503116,POHNPEI,FM,FEDERATED STATES OF MICRO
> 96942,7.138297,151.503116,CHUUK,FM,FEDERATED STATES OF MICRO
>
> COPY Command
> ------------
> COPY geo_data FROM 'geo_data2.csv' DELIMITERS ',' CSV;
>
> Error Message
> -------------
> ERROR: invalid input syntax for integer: "96799"
> CONTEXT: COPY geo_data, line 1, column id: "96799"
>
> I can't figure out why it keeps choking with "invalid syntax for
> integer" since the field was created as "text".
>
> Any and all help greatly appreciated!
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

--
Rick Genter
rick(dot)genter(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bryan Nelson 2011-07-15 17:31:40 Re: Error Importing CSV File
Previous Message Tom Lane 2011-07-15 17:10:41 Re: Error Importing CSV File