![](/img/trans.png)
[英]How to get the list of column names for all indexes on a table in PostgreSQL?
[英]PostgreSQL query to list all table names?
是否有任何查询可用于列出我的 Postgres 数据库中的所有表。
我尝试了一个查询,如:
SELECT table_name FROM information_schema.tables
WHERE table_schema='public'
但是这个查询也会返回视图。
我怎样才能只得到表名,而不是视图?
这个查询怎么样(基于手册中的描述)?
SELECT table_name
FROM information_schema.tables
WHERE table_schema='public'
AND table_type='BASE TABLE';
如果你想要数据库列表
SELECT datname FROM pg_database WHERE datistemplate = false;
如果您想要所有数据库的当前 pg 安装中的表列表
SELECT table_schema,table_name FROM information_schema.tables
ORDER BY table_schema,table_name;
使用您想要的数据库打开 postgres 终端:
psql dbname (run this line in a terminal)
然后,在 postgres 环境中运行此命令
\d
这将按名称描述所有表。 基本上是按名称升序排列的表列表。
然后你可以试试这个按字段描述表:
\d tablename.
希望这可以帮助。
试试这个:
SELECT table_name
FROM information_schema.tables
WHERE table_schema='public' AND table_type='BASE TABLE'
这个有效!
select
relname as table
from
pg_stat_user_tables
where schemaname = 'public'
select
tablename as table
from
pg_tables
where schemaname = 'public'
在psql
只给出\\dt
怎么样? 请参阅https://www.postgresql.org/docs/current/static/app-psql.html 。
SELECT table_name
FROM information_schema.tables
WHERE table_type='BASE TABLE'
AND table_schema='public';
对于 MySQL,您需要 table_schema='dbName' 并且对于 MSSQL 删除该条件。
请注意,“仅显示当前用户有权访问的那些表和视图”。 此外,如果您可以访问许多数据库并希望将结果限制在某个数据库中,您可以通过添加条件 AND table_catalog='yourDatabase'(在 PostgreSQL 中)来实现。
如果您还想去掉显示行名称的标题和显示行数的页脚,您可以使用命令行选项 -t(--tuples-only 的缩写)启动 psql,或者您可以切换 psql 中的设置\\t 的命令行(\\pset tuples_only 的缩写)。 例如,当使用 \\g [ |command ] 将输出传送到另一个命令时,这可能很有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.