From: | Bryan Nelson <shrek(at)shreks-place(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Error Importing CSV File |
Date: | 2011-07-15 17:33:34 |
Message-ID: | CAF9KfT8Duq-=qFVh2Nh9rfUtLhSQZvO0jYZu7brp+aOrfALsaA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Tom, the file was created in linunx and is utf-8. Here is the rake
task that created the table:
class CreateGeoData < ActiveRecord::Migration
def self.up
create_table :geo_data do |t|
t.column :zip_code, :text
t.column :latitude, :float8
t.column :longitude, :float8
t.column :city, :text
t.column :state, :text
t.column :county, :text
end
add_index "geo_data", ["zip_code"], :name => "zip_code_optimization"
end
def self.down
drop_table :geo_data
end
end
On Fri, Jul 15, 2011 at 1:10 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Bryan Nelson <shrek(at)shreks-place(dot)com> writes:
>> 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".
>
> It's not possible to get that error from a text field. Moreover, the
> error message clearly refers to a column named "id", which is not part
> of what you showed us, so you're not telling the whole truth here.
>
> As far as what's actually causing the problem, though, the data looks
> acceptable for an integer column, so it's pretty weird. Are you doing
> this on Windows by any chance? If so, maybe your text editor is saving
> the file with a Unicode byte order mark at the front. You'd need to
> stop it from doing that.
>
> regards, tom lane
>
From | Date | Subject | |
---|---|---|---|
Next Message | Steve Crawford | 2011-07-15 17:42:25 | Re: Error Importing CSV File |
Previous Message | Bryan Nelson | 2011-07-15 17:31:40 | Re: Error Importing CSV File |