我正在关注一本 PostgreSQL 书,并且必须将 CSV 文件导入到表中census.lu_tracts
。
问题:执行INSERT
如下所示的查询时,出现错误:
ERROR: duplicate key value violates unique constraint "pk_lu_tracts"
DETAIL: Key (tract_id)=(25001010800) already exists.
密钥是如何重复的?SELECT * from lu_tracs
显示 0 行。
CREATE SCHEMA census;
set search_path=census;
CREATE TABLE lu_tracts(tract_id varchar(11), tract_long_id varchar(25)
, tract_name varchar(150)
, CONSTRAINT pk_lu_tracts PRIMARY KEY (tract_id));
INSERT INTO lu_tracts( tract_id, tract_long_id, tract_name)
SELECT geo_id2, geo_id, geo_display
FROM staging.factfinder_import
WHERE geo_id2 ~ '^[0-9]+';