在PostgreSQL中显示表(来自MySQL)的等价物是什么?
当前回答
\dt(不需要*)--将列出您已连接到的现有数据库的所有表。还需要注意:
\d[table_name]--将显示给定表的所有列,包括类型信息、引用和键约束。
其他回答
该SQL查询适用于大多数PostgreSQL版本,非常简单。
select table_name from information_schema.tables where table_schema='public' ;
显示当前数据库的表列表
从pg_catalog.pg_tables中选择*;
select
*
from
pg_catalog.pg_tables
where
schemaname != 'information_schema'
and schemaname != 'pg_catalog';
首先,您必须连接数据库
我的数据库是ubuntu
使用此命令连接
\c ubuntu
此消息将显示
您现在以用户“postgres”的身份连接到数据库“ubuntu”
Now
运行此命令以显示其中的所有表
\d+
作为一个快速的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
推荐文章
- 查询JSON类型内的数组元素
- 获得PostgreSQL数据库中当前连接数的正确查询
- 纬度和经度的数据类型是什么?
- 如何在PostgreSQL中临时禁用触发器?
- 输入文件似乎是一个文本格式转储。请使用psql
- 使用LIMIT/OFFSET运行查询,还可以获得总行数
- 当恢复sql时,psql无效命令\N
- 货币应该使用哪种数据类型?
- 如何添加列,如果不存在PostgreSQL?
- 如何在Postgres中获得两个字段的MIN() ?
- 截断Postgres数据库中的所有表
- 如何连接列在Postgres选择?
- 将varchar字段的类型更改为整数:"不能自动转换为整数类型"
- PostgreSQL可以索引数组列吗?
- PostgreSQL:角色不允许登录