您好,登錄后才能下訂單哦!
利用PostgreSQL怎么對(duì)數(shù)據(jù)庫中的表進(jìn)行查找?相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
實(shí)現(xiàn)的功能類似MySQL:
show tables;
在 PostgreSQL 中需要寫:
select * from pg_tables where schemaname = 'public';
返回結(jié)果類似如下:
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity ------------+-----------+------------+------------+------------+----------+-------------+------------- public | deploy | postgres | | t | f | f | f public | deploy2 | postgres | | f | f | f | f (2 rows)
補(bǔ)充:PostgreSql 獲取所有的表、視圖、字段、 主鍵
PostgreSQL獲取數(shù)據(jù)庫中所有view名 視圖:
SELECT viewname FROM pg_views WHERE schemaname ='public'
postgreSQL獲取數(shù)據(jù)庫中所有table名 表:
SELECT tablename FROM pg_tables WHERE tablename NOT LIKE 'pg%' AND tablename NOT LIKE 'sql_%' ORDER BY tablename;
postgreSQL獲取某個(gè)表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獲取某個(gè)表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'
看完上述內(nèi)容,你們掌握利用PostgreSQL怎么對(duì)數(shù)據(jù)庫中的表進(jìn)行查找的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。