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


当前回答

显示当前数据库的表列表

从pg_catalog.pg_tables中选择*;

其他回答

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

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

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

作为一个快速的oneliner

# just list all the postgres tables sorted in the terminal
db='my_db_name'
clear;psql -d $db -t -c '\dt'|cut -c 11-|perl -ne 's/^([a-z_0-9]*)( )(.*)/$1/; print'

或者如果您更喜欢更清晰的json输出多行:

IFS='' read -r -d '' sql_code <<"EOF_CODE"
    select array_to_json(array_agg(row_to_json(t))) from (
        SELECT table_catalog,table_schema,table_name 
        FROM information_schema.tables
        ORDER BY table_schema,table_name ) t
EOF_CODE
psql -d postgres -t -q -c "$sql_code"|jq

可以使用\dt列出当前数据库中的表。

Fwiw,\d tablename将显示给定表的详细信息,类似于显示MySQL中tablename中的列,但提供了更多信息。

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

在PostgreSQL 13.3和Windows 10中,这些步骤对我有效

打开cmd并键入psql-a-U[用户名]-p[端口]-h[服务器]键入\c[database]以连接到数据库键入\dt或\d以显示所有表格