在PostgreSQL中显示表(来自MySQL)的等价物是什么?


当前回答

根据我的口味,在命令行列出所有表的最直接方法是:

psql -a -U <user> -p <port> -h <server> -c "\dt"

对于给定的数据库,只需添加数据库名称:

psql -a -U <user> -p <port> -h <server> -c "\dt" <database_name>

它可以在Linux和Windows上运行。

其他回答

首先,您可以使用mac上的postgre.app或postico连接postgres数据库。运行以下命令:

psql -h localhost -p port_number -d database_name -U user_name -W

然后输入密码,这应该可以访问数据库

显示当前数据库的表列表

从pg_catalog.pg_tables中选择*;

要查看psql中的外部表,请运行\dE

select 
  * 
from 
  pg_catalog.pg_tables 
where 
  schemaname != 'information_schema' 
  and schemaname != 'pg_catalog';

(为完整起见)

您还可以查询(SQL标准)信息架构:

SELECT
    table_schema || '.' || table_name
FROM
    information_schema.tables
WHERE
    table_type = 'BASE TABLE'
AND
    table_schema NOT IN ('pg_catalog', 'information_schema');