pg表中的系统列

本文介绍了PostgreSQL数据库中oid和ctid两个系统列的含义和使用。oid是对象id,在创建表时使用with oids会显示,但并非所有查询都支持。ctid表示数据行的物理位置,但因为vacuum full操作会导致位置改变,因此不适合用作行标识符。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

oid:对象id,默认是隐藏不显示的,在创建表的时候使用了with oids会显示这个列‘

select oid.* from t_test;

********** 错误 **********


ERROR: column "oid" does not exist
SQL 状态: 42703
字符:8

create table t_test (id integer,name text) with oids;

select oid,* from t_test;

16451;1;"bai"

create table as 不支持with oids

有时候知道了oid,需要看下是哪个对象

select oid,relname,relkind from pg_class where relname='t_test';

16445;"t_test";"r"

select 16445::regclass;

"t_test"

要查看这个表有哪些列

select * from pg_attribute where attrelid='t_test'::regclass;

16445;"tableoid";26;0;4;-7;0;-1;-1;t;"p";"i";t;f;f;t;0;0;"";"";""
16445;"cmax";29;0;4;-6;0;-1;-1;t;"p";"i";t;f;f;t;0;0;"";"";""
16445;"xmax";28;0;4;-5;0;-1;-1;t;"p";"i";t;f;f;t;0;0;"";"";""
16445;"cmin";29;0;4;-4;0;-1;-1;t;"p";"i";t;f;f;t;0;0;"";"";""
16445;"xmin";28;0;4;-3;0;-1;-1;t;"p";"i";t;f;f;t;0;0;"";"";""
16445;"oid";26;0;4;-2;0;-1;-1;t;"p";"i";t;f;f;t;0;0;"";"";""
16445;"ctid";27;0;6;-1;0;-1;-1;f;"p";"s";t;f;f;t;0;0;"";"";""
16445;"id";23;-1;4;1;0;-1;-1;t;"p";"i";f;f;f;t;0;0;"";"";""
16445;"name";25;-1;-1;2;0;-1;-1;f;"x";"i";f;f;f;t;0;100;"";"";""

ctid表示数据行在表内的物理位置,类型是tid,zai vaccum full之后,行在物理块中的位置会发生改变,所以ctid不能作为行标识符使用。

select ctid,id from t_test;

(0,1);1

括号中的值,0代表物理块号,第二个数字代表在物理块中的行号。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值