在PostgreSQL中显示表(来自MySQL)的等价物是什么?
当前回答
运行带有-E标志的psql将响应内部用于实现的查询\dt和类似:
sudo -u postgres psql -E
postgres=# \dt
********* QUERY **********
SELECT n.nspname as "Schema",
c.relname as "Name",
CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'i' THEN 'index' WHEN 'S' THEN 'sequence' WHEN 's' THEN 'special' END as "Type",
pg_catalog.pg_get_userbyid(c.relowner) as "Owner"
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind IN ('r','')
AND n.nspname <> 'pg_catalog'
AND n.nspname <> 'information_schema'
AND n.nspname !~ '^pg_toast'
AND pg_catalog.pg_table_is_visible(c.oid)
ORDER BY 1,2;
**************************
其他回答
select
*
from
pg_catalog.pg_tables
where
schemaname != 'information_schema'
and schemaname != 'pg_catalog';
如果您在PostgreSQL中使用pgAdmin4,可以使用它来显示数据库中的表:
select * from information_schema.tables where table_schema='public';
要查看psql中的外部表,请运行\dE
该SQL查询适用于大多数PostgreSQL版本,非常简单。
select table_name from information_schema.tables where table_schema='public' ;
从psql命令行界面,
首先,选择数据库
\c database_name
然后,这将显示当前模式中的所有表:
\dt
编程(当然也可以从psql接口):
SELECT * FROM pg_catalog.pg_tables;
系统表位于pg_catalog数据库中。
推荐文章
- 查询JSON类型内的数组元素
- 获得PostgreSQL数据库中当前连接数的正确查询
- 纬度和经度的数据类型是什么?
- 如何在PostgreSQL中临时禁用触发器?
- 输入文件似乎是一个文本格式转储。请使用psql
- 使用LIMIT/OFFSET运行查询,还可以获得总行数
- 当恢复sql时,psql无效命令\N
- 货币应该使用哪种数据类型?
- 如何添加列,如果不存在PostgreSQL?
- 如何在Postgres中获得两个字段的MIN() ?
- 截断Postgres数据库中的所有表
- 如何连接列在Postgres选择?
- 将varchar字段的类型更改为整数:"不能自动转换为整数类型"
- PostgreSQL可以索引数组列吗?
- PostgreSQL:角色不允许登录