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


当前回答

(MySQL)显示当前数据库的表列表

show tables;

(PostgreSQL)显示当前数据库的表列表

select * from pg_catalog.pg_tables where schemaname='public';

其他回答

首次以postgres用户身份登录:sudo su-后期连接到所需的数据库:psql-d databaseName\dt将返回连接到的数据库中所有表的列表。

显示当前数据库的表列表

从pg_catalog.pg_tables中选择*;

请注意,仅\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

首先使用以下命令连接数据库

\c database_name

您将看到以下消息:您现在已连接到数据库database_name。然后运行以下命令

SELECT * FROM table_name;

在database_name和table_name中,只需更新数据库和表名

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