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


当前回答

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

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

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

其他回答

首先,您必须连接数据库

我的数据库是ubuntu

使用此命令连接

 \c ubuntu

此消息将显示

您现在以用户“postgres”的身份连接到数据库“ubuntu”

Now

运行此命令以显示其中的所有表

\d+

使用仅查看表格

=> \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');
select 
  * 
from 
  pg_catalog.pg_tables 
where 
  schemaname != 'information_schema' 
  and schemaname != 'pg_catalog';

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

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