2010-02-16 34 views

回答

153

您應該可以運行select * from information_schema.tables以獲取Postgres爲特定數據庫管理的每個表的列表。

您還可以添加where table_schema = 'information_schema'以僅查看信息架構中的表。

+3

謝謝,我只是嘗試:/ DT(星號)。 (星號)是不是有什麼不同? – littleK 2010-02-16 22:10:20

+0

我不知道/ dt(星號)。(星號)的東西,對不起。我只是在postgres中運行select查詢,並列出了其中所有表的信息。 嘗試運行select語句(在您的空白數據庫)並查看它返回的內容。 – RodeoClown 2010-02-16 22:15:18

+0

嘗試上述命令列出了information_schema中的以下表:sql_features,sql_implementation_info,sql_languages,sql_packages,sql_parts,sql_sizing,sql_sizing_profiles .....那麼這些表和information_schema.tables中的表有什麼區別? – littleK 2010-02-16 22:16:50

28
\dt information_schema. 

從psql中,應該沒問題。

62

上市您的表使用:

SELECT table_name FROM information_schema.tables WHERE table_schema='public' 

將您只建立清單表。

+0

如何創建不具備訪問權限的表格? – huy 2013-03-06 09:07:30

+3

這將只顯示公共模式中的表格。您可以在其他模式中創建表格。 – 2013-07-12 20:43:01

6

您也可以

select * from pg_tables where schemaname = 'information_schema' 

使用在generall PG *表讓你看到一切都在分貝,不限制你的權限(如果你有機會到課程表)。

3

對於私人模式'xxx' PostgreSQL中:

SELECT table_name FROM information_schema.tables 
WHERE table_schema = 'xxx' AND table_type = 'BASE TABLE' 

沒有table_type = 'BASE TABLE',你會列出表格和意見

7

「\ Z」 COMMAND也列出表時的好辦法在交互式psql會話中。

例如。

# psql -d mcdb -U admin -p 5555 
mcdb=# /z 
          Access privileges for database "mcdb" 
Schema |    Name    | Type |   Access privileges 
--------+--------------------------------+----------+--------------------------------------- 
public | activities      | table | 
public | activities_id_seq    | sequence | 
public | activities_users_mapping  | table | 
[..] 
public | v_schedules_2     | view  | {admin=arwdxt/admin,viewuser=r/admin} 
public | v_systems      | view  | 
public | vapp_backups     | table | 
public | vm_client      | table | 
public | vm_datastore     | table | 
public | vmentity_hle_map    | table | 
(148 rows) 
0

如果你想快速和骯髒的單行查詢:

select * from information_schema.tables

您可以直接在查詢工具,而不必打開psql的運行它。

(其他職位提出很好的更具體的INFORMATION_SCHEMA查詢,但作爲一個牛逼,我發現這一個班輪查詢幫助我取得與該表握把)

相關問題