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


当前回答

\dt(不需要*)--将列出您已连接到的现有数据库的所有表。还需要注意:

\d[table_name]--将显示给定表的所有列,包括类型信息、引用和键约束。

其他回答

从psql命令行界面,

首先,选择数据库

\c database_name

然后,这将显示当前模式中的所有表:

\dt

编程(当然也可以从psql接口):

SELECT * FROM pg_catalog.pg_tables;

系统表位于pg_catalog数据库中。

可以使用\dt列出当前数据库中的表。

Fwiw,\d tablename将显示给定表的详细信息,类似于显示MySQL中tablename中的列,但提供了更多信息。

该SQL查询适用于大多数PostgreSQL版本,非常简单。

select table_name from information_schema.tables where table_schema='public' ;

如果您在PostgreSQL中使用pgAdmin4,可以使用它来显示数据库中的表:

select * from information_schema.tables where table_schema='public';

(为完整起见)

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

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