我试图获取PostgreSQL(9.6)中的架构列表以及可能已添加的任何评论......
这非常适合获取架构名称列表:
select schema_name
from information_schema.schemata
...但是你如何得到相关的评论(如果有的话)?
感激不尽的任何帮助!
答案 0 :(得分:2)
使用pg_namespace
select nspname as schemaname,
obj_description(oid, 'pg_namespace') as comment
from pg_namespace;
学习这样的语句的好方法是使用psql
选项运行--echo-hidden
,然后使用其中一个元命令来显示信息。
如果你是在你看到的psql中运行\dn+
:
postgres=> \dn+
********* QUERY **********
SELECT n.nspname AS "Name",
pg_catalog.pg_get_userbyid(n.nspowner) AS "Owner",
pg_catalog.array_to_string(n.nspacl, E'\n') AS "Access privileges",
pg_catalog.obj_description(n.oid, 'pg_namespace') AS "Description"
FROM pg_catalog.pg_namespace n
WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'
ORDER BY 1;
**************************
List of schemas
Name | Owner | Access privileges | Description
-----------+----------+----------------------+------------------------
public | postgres | postgres=UC/postgres+| standard public schema
| | =UC/postgres |
stuff | postgres | |
tablefunc | postgres | postgres=UC/postgres+|