SQL 如何获取所有对象的列表?- PostgreSQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3839673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get list of all objects? - PostgreSQL
提问by RadiantHex
I need a list of the objects included in the db: tables, sequences, etc...
我需要包含在 db 中的对象列表:表、序列等...
Getting the list of tables was the only thing I was able to find out.
获取表格列表是我唯一能找到的东西。
Any ideas for what I could use in order to obtain everything?
关于我可以用来获得一切的任何想法?
回答by RedFilter
You can do this using INFORMATION_SCHEMA tables, as well as the system catalog.
您可以使用 INFORMATION_SCHEMA 表以及系统目录来执行此操作。
http://www.alberton.info/postgresql_meta_info.html
http://www.alberton.info/postgresql_meta_info.html
E.g.,
例如,
List Sequences
列出序列
SELECT relname
FROM pg_class
WHERE relkind = 'S'
AND relnamespace IN (
SELECT oid
FROM pg_namespace
WHERE nspname NOT LIKE 'pg_%'
AND nspname != 'information_schema'
);
List Triggers
列出触发器
SELECT trg.tgname AS trigger_name
FROM pg_trigger trg, pg_class tbl
WHERE trg.tgrelid = tbl.oid
AND tbl.relname !~ '^pg_';
-- or
SELECT tgname AS trigger_name
FROM pg_trigger
WHERE tgname !~ '^pg_';
-- with INFORMATION_SCHEMA:
SELECT DISTINCT trigger_name
FROM information_schema.triggers
WHERE trigger_schema NOT IN
('pg_catalog', 'information_schema');