您好,登錄后才能下訂單哦!
利用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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。