[英]List all tables in postgresql information_schema
列出 PostgreSQL 的 information_schema 中所有表的最佳方法是什么?
澄清一下:我正在使用一个空数据库(我没有添加任何我自己的表),但我想查看information_schema
结构中的每个表。
您应该能够select * from information_schema.tables
运行select * from information_schema.tables
以获取Postgres为特定数据库管理的每个表的列表。
您还可以添加where table_schema = 'information_schema'
以仅查看信息架构中的表。
要列出您的表,请使用:
SELECT table_name FROM information_schema.tables WHERE table_schema='public'
它只会列出您创建的表。
\dt information_schema.
从psql内部,应该没问题。
“\\ z”命令也是在交互式psql会话中列出表的好方法。
例如。
# psql -d mcdb -U admin -p 5555
mcdb=# /z
Access privileges for database "mcdb"
Schema | Name | Type | Access privileges
--------+--------------------------------+----------+---------------------------------------
public | activities | table |
public | activities_id_seq | sequence |
public | activities_users_mapping | table |
[..]
public | v_schedules_2 | view | {admin=arwdxt/admin,viewuser=r/admin}
public | v_systems | view |
public | vapp_backups | table |
public | vm_client | table |
public | vm_datastore | table |
public | vmentity_hle_map | table |
(148 rows)
你也可以用
select * from pg_tables where schemaname = 'information_schema'
通常,pg *表允许您查看数据库中的所有内容,而不是限制您的权限(如果您当然可以访问表)。
对于postgresql中的私有模式'xxx'
:
SELECT table_name FROM information_schema.tables
WHERE table_schema = 'xxx' AND table_type = 'BASE TABLE'
如果没有table_type = 'BASE TABLE'
,您将列出表和视图
1.getgetinfo_schema.tables中的所有表和视图,包括information_schema和pg_catalog。
select * from information_schema.tables
2.get表和视图属于某种模式
select * from information_schema.tables
where table_schema not in ('information_schema', 'pg_catalog')
3.仅限表格(几乎\\ dt)
select * from information_schema.tables
where table_schema not in ('information_schema', 'pg_catalog') and
table_type = 'BASE TABLE'
如果你想要一个快速而肮脏的单行查询:
select * from information_schema.tables
您可以直接在查询工具中运行它,而无需打开psql。
(其他帖子建议更好的更具体的information_schema查询,但作为一个新的,我发现这个单行查询帮助我掌握表格)
select * from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE'
只得到你的桌子
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.