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


当前回答

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

\c database_name

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

SELECT * FROM table_name;

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

其他回答

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

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

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

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

select table_name 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');

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

\dt将列出表,\pset pager off将在同一窗口中显示它们,而不切换到单独的窗口。喜欢dbshell中的那个功能。