主頁(yè) > 知識(shí)庫(kù) > PostgreSQL 查找當(dāng)前數(shù)據(jù)庫(kù)的所有表操作

PostgreSQL 查找當(dāng)前數(shù)據(jù)庫(kù)的所有表操作

熱門(mén)標(biāo)簽:漯河外呼電話系統(tǒng) 合肥公司外呼系統(tǒng)運(yùn)營(yíng)商 打電話智能電銷機(jī)器人授權(quán) 美容工作室地圖標(biāo)注 重慶自動(dòng)外呼系統(tǒng)定制 地圖標(biāo)注和圖片名稱的區(qū)別 辦公外呼電話系統(tǒng) 海豐有多少商家沒(méi)有地圖標(biāo)注 外呼調(diào)研系統(tǒng)

實(shí)現(xiàn)的功能類似MySQL:

show tables;

在 PostgreSQL 中需要寫(xiě):

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ù)庫(kù)中所有view名 視圖:

SELECT viewname FROM pg_views 
WHERE  schemaname ='public' 

postgreSQL獲取數(shù)據(jù)庫(kù)中所有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'

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

您可能感興趣的文章:
  • PostgreSQL 自動(dòng)Vacuum配置方式
  • PHP實(shí)現(xiàn)從PostgreSQL數(shù)據(jù)庫(kù)檢索數(shù)據(jù)分頁(yè)顯示及根據(jù)條件查找數(shù)據(jù)示例
  • PostgreSQL 如何查找需要收集的vacuum 表信息

標(biāo)簽:錦州 蚌埠 烏海 珠海 衡陽(yáng) 晉城 來(lái)賓 株洲

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PostgreSQL 查找當(dāng)前數(shù)據(jù)庫(kù)的所有表操作》,本文關(guān)鍵詞  PostgreSQL,查找,當(dāng)前,數(shù)據(jù)庫(kù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《PostgreSQL 查找當(dāng)前數(shù)據(jù)庫(kù)的所有表操作》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于PostgreSQL 查找當(dāng)前數(shù)據(jù)庫(kù)的所有表操作的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章