pg_get_object_address
返回值含义:
- 第一列:从哪张系统表可以查到对象信息?
- 第二列:到的对象信息在系统表中的OID?
入参含义:
代码语言:javascript复制pg_describe_object(PG_FUNCTION_ARGS)
{
Oid classid = PG_GETARG_OID(0);
Oid objid = PG_GETARG_OID(1);
int32 objsubid = PG_GETARG_INT32(2);
...
实例
代码语言:javascript复制-- 2615: pg_namespace(from pg_class)
-- 2200: public(from pg_namespace)
postgres=# SELECT pg_get_object_address('schema', '{public}', '{t1}');
pg_get_object_address
-----------------------
(2615,2200,0)
-- 1259: pg_class(from pg_class)
-- 16398: t1(from pg_class)
SELECT pg_get_object_address('table', '{t1}', '{}');
pg_get_object_address
-----------------------
(1259,16398,0)
入参类型
文档并没有说明参数1都能传入哪些值,从代码中看可以支持以下类型,记录在下表便于查找。
代码语言:javascript复制// 参数1用ObjectTypeMap做字符串匹配
pg_get_object_address
char *ttype = TextDatumGetCString(PG_GETARG_DATUM(0));
itype = read_objtype_from_string(ttype);
if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
ObjectTypeMap[] =
{
/* OCLASS_CLASS, all kinds of relations */
{
"table", OBJECT_TABLE
},
{
"index", OBJECT_INDEX
},
{
"sequence", OBJECT_SEQUENCE
},
{
"toast table", -1
}, /* unmapped */
{
"view", OBJECT_VIEW
},
{
"materialized view", OBJECT_MATVIEW
},
{
"composite type", -1
}, /* unmapped */
{
"foreign table", OBJECT_FOREIGN_TABLE
},
{
"table column", OBJECT_COLUMN
},
{
"index column", -1
}, /* unmapped */
{
"sequence column", -1
}, /* unmapped */
{
"toast table column", -1
}, /* unmapped */
{
"view column", -1
}, /* unmapped */
{
"materialized view column", -1
}, /* unmapped */
{
"composite type column", -1
}, /* unmapped */
{
"foreign table column", OBJECT_COLUMN
},
/* OCLASS_PROC */
{
"aggregate", OBJECT_AGGREGATE
},
{
"function", OBJECT_FUNCTION
},
{
"procedure", OBJECT_PROCEDURE
},
/* OCLASS_TYPE */
{
"type", OBJECT_TYPE
},
/* OCLASS_CAST */
{
"cast", OBJECT_CAST
},
/* OCLASS_COLLATION */
{
"collation", OBJECT_COLLATION
},
/* OCLASS_CONSTRAINT */
{
"table constraint", OBJECT_TABCONSTRAINT
},
{
"domain constraint", OBJECT_DOMCONSTRAINT
},
/* OCLASS_CONVERSION */
{
"conversion", OBJECT_CONVERSION
},
/* OCLASS_DEFAULT */
{
"default value", OBJECT_DEFAULT
},
/* OCLASS_LANGUAGE */
{
"language", OBJECT_LANGUAGE
},
/* OCLASS_LARGEOBJECT */
{
"large object", OBJECT_LARGEOBJECT
},
/* OCLASS_OPERATOR */
{
"operator", OBJECT_OPERATOR
},
/* OCLASS_OPCLASS */
{
"operator class", OBJECT_OPCLASS
},
/* OCLASS_OPFAMILY */
{
"operator family", OBJECT_OPFAMILY
},
/* OCLASS_AM */
{
"access method", OBJECT_ACCESS_METHOD
},
/* OCLASS_AMOP */
{
"operator of access method", OBJECT_AMOP
},
/* OCLASS_AMPROC */
{
"function of access method", OBJECT_AMPROC
},
/* OCLASS_REWRITE */
{
"rule", OBJECT_RULE
},
/* OCLASS_TRIGGER */
{
"trigger", OBJECT_TRIGGER
},
/* OCLASS_SCHEMA */
{
"schema", OBJECT_SCHEMA
},
/* OCLASS_TSPARSER */
{
"text search parser", OBJECT_TSPARSER
},
/* OCLASS_TSDICT */
{
"text search dictionary", OBJECT_TSDICTIONARY
},
/* OCLASS_TSTEMPLATE */
{
"text search template", OBJECT_TSTEMPLATE
},
/* OCLASS_TSCONFIG */
{
"text search configuration", OBJECT_TSCONFIGURATION
},
/* OCLASS_ROLE */
{
"role", OBJECT_ROLE
},
/* OCLASS_DATABASE */
{
"database", OBJECT_DATABASE
},
/* OCLASS_TBLSPACE */
{
"tablespace", OBJECT_TABLESPACE
},
/* OCLASS_FDW */
{
"foreign-data wrapper", OBJECT_FDW
},
/* OCLASS_FOREIGN_SERVER */
{
"server", OBJECT_FOREIGN_SERVER
},
/* OCLASS_USER_MAPPING */
{
"user mapping", OBJECT_USER_MAPPING
},
/* OCLASS_DEFACL */
{
"default acl", OBJECT_DEFACL
},
/* OCLASS_EXTENSION */
{
"extension", OBJECT_EXTENSION
},
/* OCLASS_EVENT_TRIGGER */
{
"event trigger", OBJECT_EVENT_TRIGGER
},
/* OCLASS_POLICY */
{
"policy", OBJECT_POLICY
},
/* OCLASS_PUBLICATION */
{
"publication", OBJECT_PUBLICATION
},
/* OCLASS_PUBLICATION_REL */
{
"publication relation", OBJECT_PUBLICATION_REL
},
/* OCLASS_SUBSCRIPTION */
{
"subscription", OBJECT_SUBSCRIPTION
},
/* OCLASS_TRANSFORM */
{
"transform", OBJECT_TRANSFORM
},
/* OCLASS_STATISTIC_EXT */
{
"statistics object", OBJECT_STATISTIC_EXT
}
};