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代表物理块号,第二个数字代表在物理块中的行号。