Skip to content

Instantly share code, notes, and snippets.

@yuhangch
Created March 7, 2020 09:22
Show Gist options
  • Save yuhangch/c96849a389e3fd0dff92735a142acde6 to your computer and use it in GitHub Desktop.
Save yuhangch/c96849a389e3fd0dff92735a142acde6 to your computer and use it in GitHub Desktop.
Delete Repeat Records in Postgresql
--将数据去重后存入临时表,PostgreSQL会自动创建tmp_table以及表结构
select distinct * into tmp_table from repeat_table;
--删除原记录
delete from repeat_table;
--将临时表数据插入原表
insert into repeat_table select * from tmp_table;
--删除临时表
drop table tmp_table;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment