是的,有tableoid
system column个,就是为了这个:
一百零二
包含此行的表的OID.对于从分区表(请参见Section 5.11)或inheritance hierarchies(请参见Section 5.10)中进行 Select 的查询,该列特别方便,因为如果没有它,就很难判断行来自哪个单独的表.可以将tableoid
与pg_class
的oid
列联接以获得表名.
Demo:
create table "Payments"(id int);
create table "SubscriptionPayments"() inherits ("Payments");
create table "OrderPayments"() inherits ("Payments");
insert into "Payments" select 1;
insert into "SubscriptionPayments" select 2;
insert into "OrderPayments" select 3;
select * from "Payments";
即使请求了all列,Payments
中的所有记录似乎也无法区分:
这是因为默认情况下,除非显式列出,否则系统列是隐藏的,因此您需要在列表中添加tableoid
.它是一个oid
(可读性不是很好),但可以通过转换为regclass
将其转换为实际的表名:
select tableoid, tableoid::regclass, * from "Payments";
<头>
Tableid |
Tableid |
id |
<正文>
16384 |
"付款" |
1 |
16387 |
"订阅支付" |
2 |
16390 |
"OrderPayments" |
3 |