postgresql delete duplicated rows

Deleting duplicates

使用window function row_number 对数据partition

举例:

isnp=# create table student (id serial,name text,age int);
isnp=# \d student;
isnp=# with cte as (select *,round(random()*100) as d from generate_series(1,10000) as r) insert into student (name,age)  select 'lmy'||r,d from cte;
### genetate duplicate row
isnp=# insert into student (name,age) select name,age from student where 100<id and id<200; 
isnp=# with xxx (id,name,age,rn)  as (select *,row_number() over(partition by name order by id) rn from student) delete from student where id in (select id from xxx where rn > 1);

相关文章

来源:http://www.postgres.cn/docs/11/ 4.1.1.&#160;标识符和关键词 SQL标识符和关键词必须以一个...
来源:http://www.postgres.cn/docs/11/ 8.1.&#160;数字类型 数字类型由2、4或8字节的整数以及4或8...
来源:http://www.postgres.cn/docs/11/ 5.1.&#160;表基础 SQL并不保证表中行的顺序。当一个表被读...
来源:http://www.postgres.cn/docs/11/ 6.4.&#160;从修改的行中返回数据 有时在修改行的操作过程中...
来源:http://www.postgres.cn/docs/11/ 13.2.1.&#160;读已提交隔离级别 读已提交是PostgreSQL中的...
来源:http://www.postgres.cn/docs/11/ 9.7.&#160;模式匹配 PostgreSQL提供了三种独立的实现模式匹...