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


当前回答

请注意,仅\dt将列出您正在使用的数据库的公共模式中的表。我喜欢将表保存在单独的模式中,因此接受的答案对我来说不起作用。

要列出特定模式中的所有表,我需要:

1) 连接到所需的数据库:

psql mydb

2) 指定要在\dt命令后查看表的架构名称,如下所示:

\dt myschema.*

这显示了我感兴趣的结果:

               List of relations
 Schema   |       Name      | Type  |  Owner   
----------+-----------------+-------+----------
 myschema | users           | table | postgres
 myschema | activity        | table | postgres
 myschema | roles           | table | postgres

其他回答

使用仅查看表格

=> \dt

如果要查看架构表

=>\dt+

如果要查看特定的架构表

=>\dt schema_name.* 

(为完整起见)

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

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

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

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

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

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

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

从psql命令行界面,

首先,选择数据库

\c database_name

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

\dt

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

SELECT * FROM pg_catalog.pg_tables;

系统表位于pg_catalog数据库中。