☆☆☆★☆☆☆

唯有努力才能活成自己想要活成的样子

导航

postger数据库使用开窗函数删除表内重复数据

使用id字段开窗(也可以多个字段,但是any函数和arry函数需要替换)

select *  from gatherdata.temp_zyr_export_1  a where a.linkid = any(array (
select linkid from (
select row_number() over (partition by linkid), linkid from gatherdata.temp_zyr_export_1
) t where t.row_number > 1
));

 利用ctid删除重复的数据(ctid是PG表中的系统字段,表示数据行在它所在表内的物理位置。ctid的字段类型是oid。但是VACUUM FULL操作之后,经过回收数据块内的空闲空间,数据行在块内的物理位置会发生移动,即ctid会发生变化)

explain analyze delete from gatherdata.iov_vehicle_day_event a 
where a.ctid = any(array (
select ctid from (select row_number() over (partition by terminal_id,clct_date), ctid from gatherdata.iov_vehicle_day_event where clct_date =20231009) t where t.row_number > 1));

 

posted on 2023-08-10 14:52  Yr-Zhang  阅读(61)  评论(0编辑  收藏  举报