在PostgreSQL表中导入CSV文件(重复行)

时间:2017-08-03 11:03:07

标签: sql postgresql

我需要完成查询以从临时表tmp_x添加表CREATE TEMP TABLE tmp_x AS SELECT * FROM testcsv2 LIMIT 0; COPY tmp_x FROM 'D:\water_utility2.csv' (FORMAT csv); UPDATE testcsv2 SET record = tmp_x.record, "Battery Voltage" = tmp_x."Battery Voltage" FROM tmp_x WHERE testcsv2.timestamp = tmp_x.timestamp; DROP TABLE tmp_x; 中不存在的行:

TABLE testcsv2 
(TIMESTAMP timestamp, RECORD double precision, "Battery Voltage" double precision);

请帮帮我吗?

更新

tmp_x

2009-12-31 23:00:00,112086,13.56197 2009-12-31 23:15:00,102087,23.56113 2009-12-31 23:30:00,102088,13.56449 2010-01-01 23:45:00,102089,13.57373 具有相同的列。填写来自csv的那个:

combn

1 个答案:

答案 0 :(得分:0)

试试这个:

insert into testcsv2 select * from (
select x.* 
from tmp_x x
left outer join testcsv2 t on t. timestamp = x. timestamp
where t. timestamp is null
) as missing;