PostgreSQL COPY CSV ERROR:最后一个预期列之后的额外数据 [英] Postgresql COPY CSV ERROR: extra data after last expected column

查看:5119
本文介绍了PostgreSQL COPY CSV ERROR:最后一个预期列之后的额外数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从导入数据,网址为:http://www.unitedstateszipcodes.org/zip-code-database 。数据的子集如下:

I'm trying to import the data from http://www.unitedstateszipcodes.org/zip-code-database. A subset of the data looks like this:

"zip","type","primary_city","acceptable_cities","unacceptable_cities","state","county","timezone","area_codes","latitude","longitude","world_reg$
"00501","UNIQUE","Holtsville",,"I R S Service Center","NY","Suffolk County","America/New_York","631","40.81","-73.04","NA","US","0","384",
"00544","UNIQUE","Holtsville",,"Irs Service Center","NY","Suffolk County","America/New_York","631","40.81","-73.04","NA","US","0","0"

我运行的postgresql命令是:

The postgresql command I running is this:

copy development.zip_codes FROM '/tmp/zip_code_database.csv' WITH DELIMITER ',' CSV HEADER;

结果如下:

ERROR: extra data after last expected column
SQL state: 22P04
Context: COPY zip_codes, line 2: ""00501","UNIQUE","Holtsville",,"I R S Service Center","NY","Suffolk County","America/New_York","631"..."

我在做错误的导入?

推荐答案



Works like a charm, here ...

DROP TABLE zipcodes CASCADE;
CREATE TABLE zipcodes
        ( id serial NOT NULL PRIMARY KEY
        , zzip varchar NOT NULL UNIQUE
        , ztype varchar
        , primary_city varchar
        , acceptable_cities varchar
        , unacceptable_cities varchar
        , state varchar
        , county varchar
        , ztimezone varchar
        , area_codes varchar
        , latitude varchar
        , longitude varchar
        , world_region varchar
        , country varchar
        , decommissioned varchar
        , estimated_population varchar
        , notes varchar
        ); 

COPY zipcodes (zzip,ztype,primary_city
     , acceptable_cities,unacceptable_cities
     , state,county,ztimezone,area_codes 
     , latitude,longitude,world_region,country
     , decommissioned,estimated_population,notes )
FROM '/tmp/zip_code_database.csv'
        WITH CSV HEADER delimiter ','
        ;

结果:

DROP TABLE
CREATE TABLE
COPY 42522

OP有CR / CRLF问题?)

(maybe the OP has CR/CRLF problems ?)

这篇关于PostgreSQL COPY CSV ERROR:最后一个预期列之后的额外数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆