PostgreSql中使用ctid去重
来源:互联网 发布:练小提琴的软件 编辑:程序博客网 时间:2024/06/03 18:47
最近的开发中使用PostgreSql时也遇到了去重的问题,开始的时候确实一筹莫展,不像Oracle有rowid这样的字段(是因为我不知道pg中也有类似的字段),因此就在文档中找类似的字段,于是想起了几个系统字段来,这边着重就看解决问题的ctid。
ctid是一个表中物理上确认版本的字段,这是个系统字段,只要表中存在数据那么就会存在这个字段,与oid不同。要想使用OID,创建表时应该带上with oid。
在一个表中ctid是唯一的,那么就符合了去重的先决条件。于是,在下面的情况下,
"ctid" "id""name_1" "name_2""name_3"
"(0,133)" "3" "name_13" "name_23""name4444"
"(1,119)" "3" "name_13" "name_23""name4444"
很明显两条数据一样,只需要保留一条。那么就得这样做,
select * from mytest6 where ctid in (
select min(ctid) from mytest6 where id = 3);
当然这是知道只有id=3时会出现这样的情况,假如不止这一条,那么就得这么做,
select * from mytest where ctid in (
select min(ctid) from mytest group by id);
写法可以很多,也可以不用in,而使用表关联。但是大致的解决思路就是这样。
0 0
- PostgreSql中使用ctid去重
- oracle rowid and postgresql ctid
- postgresql 系统字段 tableoid,xmin,cmin,xmax,cmax,ctid
- PostgreSQL attr correlation for values(logical order) & ctid (physcial order)
- 关于STL中vector使用unique()去重的问题
- 关于STL中vector使用unique()去重的问题
- 关于STL中vector使用unique()去重
- c++中set的使用:初始化和去重、排序
- 在mysql中使用去重distinct需要注意的
- 字符串中字符去重
- python中list去重
- list中对象去重
- Python中list去重
- java中List去重
- Java中List去重
- python中数组去重
- 【Python】使用Bloomfilter去重
- postgresql中使用dblink
- 实时显示iOS编写UI代码效果
- Java运算符优先级
- ps 图层样式
- hdu4804 Campus Design 插头DP
- 2015年东北四省区域赛——B题题解(Matrix)
- PostgreSql中使用ctid去重
- xcode反汇编调试iOS模拟器程序(七)Debug与Release的区别
- POJ 1080
- Could not calculate build plan: Plugin org.apache.maven.plugins:maven-war-plugin:2.3
- oracle静默安装文件db_install.rsp详解
- 态度
- Ubuntu 14.04上驱动开发环境配置,及最简单一个驱动编写。
- 用css对webkit内核的浏览器自定义滚动条
- UIPickerView