PostgreSQL bulk import from CSV failing. ERROR: invalid input syntax for integer: "1990-01-02" -
i importing data csv file postgresql table.
the table looks this:
create table foo_stats ( td date not null, ins_id integer check (ins_id > 0) not null, df_id integer check (df_id > 0) not null, pc real not null default 0.0, ph real default 0.0 not null, pl real default 0.0 not null, av real default 0.0 not null, cv bigint default 0 not null, avi real default 0.0 not null, cmi bigint default 0 not null, vwp real check (vwp >= 0) not null, atr real not null default -99999, pv real not null default -99999, pr real not null default -99999, primary key (ins_id, df_id, td) );
before bulk copy, drop primary key using alter table drop constraint primary key
here trace of cl when invoke copy
command @ psql cli:
mydb=# copy foo_stats '/path/to/data/foo_stats.csv' csv; error: invalid input syntax integer: "1990-01-02" context: copy foo_stats, line 1, column id: "1990-01-02" mydb=#
here first few lines of input csv file looks like:
"1990-01-02",388,3,-99999,0.913,0.91,0.0,0,0.0,0,0,-99999,-99999,-99999 "1990-01-02",388,4,-99999,0.913,0.91,0.0,0,0.0,0,0,-99999,-99999,-99999 "1990-01-02",388,1,-99999,0.913,0.91,0.0,0,0.0,0,0,-99999,-99999,-99999 "1990-01-02",388,7,-99999,0.913,0.91,0.0,0,0.0,0,0,-99999,-99999,-99999 "1990-01-02",388,6,-99999,0.913,0.91,0.0,0,0.0,0,0,-99999,-99999,-99999
the data columns in input file in same order in table schema. can explain why getting error message?
ps: using postgresql 8.4 on ubuntu 10.0.4 lts
cutting , pasting table definition , sample data here shows working.
so - either table definition or file not think are. if table columns in different order, can specify columns in copy command.
if file different, it's presumably not visible naked eye, or have spotted before asking. don't suppose file has come windows machine chance?
three things check for:
- unnecessary byte-order-mark (bom) @ start of file
- line-endings of \r\n rather \n
- any other control-codes
try cutting + pasting sample data , see if imports. if so, try opening real file in text editor , re-saving it. if fixes things, hex editor , take @ actual bytes in sample file.
Comments
Post a Comment