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


当前回答

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

show tables;

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

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

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

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

从psql命令行界面,

首先,选择数据库

\c database_name

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

\dt

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

SELECT * FROM pg_catalog.pg_tables;

系统表位于pg_catalog数据库中。

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


使用psql:\dt

Or:

SELECT c.relname AS Tables_in FROM pg_catalog.pg_class c
        LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE pg_catalog.pg_table_is_visible(c.oid)
        AND c.relkind = 'r'
        AND relname NOT LIKE 'pg_%'
ORDER BY 1