实现的功能类似MySQL:

show tables;

在 PostgreSQL 中需要写:

select * from pg_tables where schemaname = 'public';

返回结果类似如下:

schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity 
------------+-----------+------------+------------+------------+----------+-------------+-------------
 public  | deploy | postgres |   | t   | f  | f   | f
 public  | deploy2 | postgres |   | f   | f  | f   | f
(2 rows)

补充:PostgreSql 获取所有的表、视图、字段、 主键

PostgreSQL获取数据库中所有view名 视图:

SELECT viewname FROM pg_views 
WHERE  schemaname ='public' 

postgreSQL获取数据库中所有table名 表:

SELECT tablename FROM pg_tables 
WHERE tablename NOT LIKE 'pg%' 
AND tablename NOT LIKE 'sql_%'
ORDER BY tablename;

postgreSQL获取某个表tablename 所有字段名称 , 类型,备注,是否为空 等

SELECT col_description(a.attrelid,a.attnum) as comment,pg_type.typname as typename,a.attname as name, a.attnotnull as notnull
FROM pg_class as c,pg_attribute as a inner join pg_type on pg_type.oid = a.atttypid
where c.relname = 'tablename' and a.attrelid = c.oid and a.attnum>0

postgreSQL获取某个表tablename 的主键信息

select pg_attribute.attname as colname,pg_type.typname as typename,pg_constraint.conname as pk_name from 
pg_constraint inner join pg_class 
on pg_constraint.conrelid = pg_class.oid 
inner join pg_attribute on pg_attribute.attrelid = pg_class.oid 
and pg_attribute.attnum = pg_constraint.conkey[1]
inner join pg_type on pg_type.oid = pg_attribute.atttypid
where pg_class.relname = 'tablename' 
and pg_constraint.contype='p'

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。

标签:
PostgreSQL,查找数据库表

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

评论“PostgreSQL 查找当前数据库的所有表操作”

暂无“PostgreSQL 查找当前数据库的所有表操作”评论...

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。