postgresql 如何在 Redshift 中列出所有表及其创建者(或所有者)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29853079/
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 list all tables and their creators (or owners) in Redshift
提问by kee
I thought it is straightforward but I couldn't find a way to list all tables and their creators (or owners) in Redshift. Any help/insight is welcome.
我认为这很简单,但我找不到在 Redshift 中列出所有表及其创建者(或所有者)的方法。欢迎任何帮助/见解。
回答by kee
It was pg_tables table and here is the SQL:
这是 pg_tables 表,这里是 SQL:
select tablename, tableowner From pg_tables
回答by LiriB
You can list Redshift tables, views and their owners by running this script:
您可以通过运行以下脚本列出 Redshift 表、视图及其所有者:
SELECT n.nspname AS schema_name
, pg_get_userbyid(c.relowner) AS table_owner
, c.relname AS table_name
, CASE WHEN c.relkind = 'v' THEN 'view' ELSE 'table' END
AS table_type
, d.description AS table_description
FROM pg_class As c
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_tablespace t ON t.oid = c.reltablespace
LEFT JOIN pg_description As d
ON (d.objoid = c.oid AND d.objsubid = 0)
WHERE c.relkind IN('r', 'v')
ORDER BY n.nspname, c.relname ;