我可以使用列出所有模式中的所有表

> dt *.*

但是这也列出了系统表,这些表的数量远远超过了我关心的表.我喜欢我在公共模式中创建的所有表(以及可能的视图)以及我定义的任何模式.

我希望找到一种方法来实现这一点,而无需在搜索路径中显式添加模式,因为我按照此处的描述创建它们:

https://stackoverflow.com/a/12902069

编辑:

根据接受的答案,我创建了以下视图:

create view my_tables as 
select table_catalog, table_schema, table_name, table_type 
from information_schema.tables 
where table_schema not in ('pg_catalog', 'information_schema');

现在,以下命令给了我想要的东西:

select * from my_tables;

这将列出当前用户有权访问的所有表,而不仅仅是当前用户拥有的表:

select *
from information_schema.tables
where table_schema not in ('pg_catalog', 'information_schema')
and table_schema not like 'pg_toast%'

(我不完全确定实际上不需要’pg_toast%’.)

我真的需要所有者信息,您可能需要使用pg_class和相关表.

编辑:这是包含所有者信息的查询:

select nsp.nspname as object_schema,
       cls.relname as object_name, 
       rol.rolname as owner, 
       case cls.relkind
         when 'r' then 'TABLE'
         when 'm' then 'MATERIALIZED_VIEW'
         when 'i' then 'INDEX'
         when 'S' then 'SEQUENCE'
         when 'v' then 'VIEW'
         when 'c' then 'TYPE'
         else cls.relkind::text
       end as object_type
from pg_class cls
  join pg_roles rol on rol.oid = cls.relowner
  join pg_namespace nsp on nsp.oid = cls.relnamespace
where nsp.nspname not in ('information_schema', 'pg_catalog')
  and nsp.nspname not like 'pg_toast%'
  and rol.rolname = current_user  --- remove this if you want to see all objects
order by nsp.nspname, cls.relname;