so=# create function t.fn() returns int as
$$
begin return 1; end; $$ language plpgsql;
CREATE FUNCTION
so=# comment on function t.fn() is 'some comment';
COMMENT
so=# select * from obj_description('t.fn'::regproc);
obj_description
-----------------
some comment
(1 row)
regclass 用于关系,用于函数使用regproc
更新
https://www.postgresql.org/docs/current/static/functions-info.html#FUNCTIONS-INFO-COMMENT-TABLE
obj_description 的两参数形式返回一个注释
由其 OID 和包含的名称指定的数据库对象
系统目录。例如,obj_description(123456,'pg_class') 会
检索具有 OID 123456 的表的注释。一个参数
obj_description 的形式只需要对象 OID。已弃用
因为不能保证 OID 在不同的
系统目录;因此,可能会返回错误的评论。
函数oids存储在pg_proc中,表和视图存储在pg_class中(分别为relkindr和v),因此:
select * from obj_description('t.fn'::regproc)
-
pg_class 用于表和视图,pg_proc 用于函数
- 以下是查询:
对于所有函数(我添加order 和limit 以显示UDF 小列表):
so=# select oid::regproc,obj_description(oid,tableoid::regclass::text)
from pg_proc
order by oid desc
limit 2;
oid | obj_description
------+-----------------
t.fn | some comment
a | blah
(2 rows)
对于所有表格:
so=# select oid::regclass,obj_description(oid,tableoid::regclass::text) from pg_class where relkind = 'r' order by oid desc limit 1;
oid | obj_description
---------------+---------------------
t."WeirdMix$" | table with bad name
(1 row)
分别用于查看:
so=# select oid::regclass,obj_description(oid,tableoid::regclass::text) from pg_class where relkind = 'v' order by oid desc limit 1;
oid | obj_description
-----+-----------------
v | view this is
(1 row)