您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
利用PostgreSQL怎么对数据库中的表进行查找?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
实现的功能类似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怎么对数据库中的表进行查找的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。