2012-12-18 52 views
25

有什麼辦法可以讓我得到Postgresql數據庫中的表總數?我使用的postgresql版本是PostgreSQL 8.4.14。如何獲取postgresql中的表總數?

+0

探討什麼事情只在一個數據庫中,我通常使用'\ d'。有了這個,你可以列出表格,視圖和序列的總數。 – omar

回答

30
select count(*) 
from information_schema.tables; 

或者,如果你想找到的表的數量只爲一個特定的模式:

select count(*) 
from information_schema.tables 
where table_schema = 'public'; 
+0

如果我們要計算表的數量,該怎麼辦?我知道我們可以看到數字,但我想在sql語句中使用這個數字? – bukowski

13

只要嘗試在pg_stat ... tables或information_schema中搜索,就可以找到關於數據庫的非常有用的信息。
例子:

select * from pg_stat_user_tables ; 
select count(*) from pg_stat_user_tables ; 
select * from pg_stat_all_tables ; 
-3
select Count(*) from sys.tables 
+2

這應該適用於SQL Server,對吧?不是PostgreSQL。 – xnakos

+1

這對Postgres無效。 –

相關問題