如何在Redshift中列出所有表及其创建者(或所有者)

时间:2015-04-24 16:46:13

标签: postgresql amazon-redshift

我认为这很简单,但我找不到在Redshift中列出所有表格及其创建者(或所有者)的方法。欢迎任何帮助/见解。

2 个答案:

答案 0 :(得分:6)

这是pg_tables表,这是SQL:

select tablename, tableowner From pg_tables 

答案 1 :(得分:1)

您可以通过运行以下脚本列出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 ;