在PostgreSQL中获取表注释列表 [英] Getting list of table comments in PostgreSQL
问题描述
Postgresql允许向表等对象添加注释。例如,我使用此SQL命令在表 mytable上添加了注释:
Postgresql allows adding comments to objects such as tables. For example I've added a comment to table "mytable" by using this SQL command:
COMMENT ON TABLE mytable IS 'This is my table.';
我的问题是:
如果我想使用SQL命令获取所有表以及他们各自的评论-我该怎么做?
My question is: If I want to use a SQL-command to get all tables along with their respective comment - how would I do this? What would be the appropriate query for this?
预先感谢!
干杯!
Thanks in advance! Cheers!
推荐答案
所有注释都存储在 pg_description
要获取表中的注释,您可以需要将其加入 pg_class
To get the comments on a table, you need to join it to pg_class
作为替代方案,您也可以使用函数 obj_description()
来检索以下信息:
As an alternative you can also use the function obj_description()
to retrieve this information:
SELECT obj_description(oid)
FROM pg_class
WHERE relkind = 'r'
编辑
在psql中,您可以简单地使用 \d +
命令显示所有表及其注释。或使用 \dd
命令显示系统中的所有注释
In psql you can simply use the \d+
command to show all tables including their comments. Or use the \dd
command to show all comments in the system
这篇关于在PostgreSQL中获取表注释列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!