postgresql - 导入 TXT 文件时在 Postgresql 中添加“自动递增主键”列
问题描述
我正在尝试在我的表中导入 .txt 文件。唯一的问题是它在导入时给了我一条错误消息
ERROR: missing data for column "id"
CONTEXT: COPY tmp_x, line 1: "15.06.18|1:00|11.6|11.6|10.8|96|11.0|9.7|SE|9.66|16.1|SE|10.6|11.8|10.8||753.9|0.20|0.0|0|0.00|0|0.0..."
SQL state: 22P04
SQL查询是这样的:
CREATE TEMP TABLE tmp_x AS SELECT * FROM weather LIMIT 0; -- but see below
COPY tmp_x FROM PROGRAM 'more +3 "D:\Users\h.yordanov\Desktop\downld08.txt"' (FORMAT csv, DELIMITER '|');
insert into weather select * from (
select x.*
from tmp_x x
left outer join weather t on t. date1 = x. date1
where t. date1 is null
) as missing;
DROP TABLE tmp_x; -- else it is dropped at end of session automatically
.txt 文件中包含以下数据:
|Temp|Hi|Low|Out|Dew|Wind|Wind|Wind|Hi|Hi|Wind|Heat|THW|THSW|Rain|Solar|Solar|Hi|Solar|UV|UV|Hi|Heat|Cool|In|In|In|In|In|In|Air|Wind|Wind|ISS|Arc
|Date|Time|Out|Temp|Temp|Hum|Pt.|Speed|Dir|Run|Speed|Dir|Chill|Index|Index|Index|Bar|Rain|Rate|Rad.|Energy|Rad.|Index|Dose|UV|DD|DD|Temp|Hum|Dew|Heat|EMC|Density|ET|Samp|Tx|Recept|Int
15.06.18|1:00|11.6|11.6|10.8|96|11.0|9.7|SE|9.66|16.1|SE|10.6|11.8|10.8||753.9|0.20|0.0|0|0.00|0|0.0|0.00|0.0|0.280|0.000|13.1|52|3.4|12.1|9.84|1.2145|0.00|1393|1|100.0|60
和表:
CREATE TABLE weather
(
id SERIAL PRIMARY KEY,
Date1 date,
Time1 time,
"Temp Out" double precision,
"Hi Temp" double precision,
"Low Temp" double precision,
"Out Hum" double precision,
"Dew Pt." double precision,
"Wind Speed" double precision,
"Wind Dir" character varying,
"Wind Run" double precision,
"Hi Speed" double precision,
"Hi Dir" character varying,
"Wind Chill" double precision,
"Heat Index" double precision,
"THW Index" double precision,
"THSW Index" double precision,
"Bar" double precision,
"Rain" double precision,
"Rain Rate" double precision,
"Solar Rad" integer,
"Solar Energy" double precision,
"Hi Solar Energy" double precision,
"UV Index" double precision,
"UV Dose" double precision,
"Hi UV" double precision,
"Heat DD" double precision,
"Cool DD" double precision,
"In temp" double precision,
"In Hum" double precision,
"In Dew" double precision,
"In Heat" double precision,
"In EMC" double precision,
"In Air Density" double precision,
"ET" double precision,
"Wind Stamp" double precision,
"Wind Tx" double precision,
"ISS Recept" double precision,
"Arc Int" double precision);
任何想法如何解决这个问题。也许问题出在临时表中?我已经在网上搜索过,但我没有看到任何关于这种情况的信息。
解决方案
推荐阅读
- ios - SwiftUI 和 iOS 应用向后兼容
- c# - .NET Core 3.1 中的链式依赖注入
- java - 使用 Fortify 将字段设置为 null 时的 Java Null 取消引用
- macos - 从 NSItemProvider 获取文件名/路径
- python - Python Regex Sentence Finder - 想要忽略“am”
- kubernetes - Kubernetes 容器命令启动一个不停止的 bash
- docker - K8s DNS 解析不适用于所有 pod
- c# - C# - 为什么 Array.Clone() 需要强制转换?
- arrays - 我们是否必须创建一个偶数和一个奇数数组?
- reactjs - 如何在 React 中的两个组件之间传递对象和状态