在PostgreSQL的information_schema中列出所有表的最佳方式是什麼?列出postgresql中的所有表information_schema
澄清:我正在處理一個空的數據庫(我沒有添加任何自己的表),但我想查看information_schema結構中的每個表。
在PostgreSQL的information_schema中列出所有表的最佳方式是什麼?列出postgresql中的所有表information_schema
澄清:我正在處理一個空的數據庫(我沒有添加任何自己的表),但我想查看information_schema結構中的每個表。
您應該可以運行select * from information_schema.tables
以獲取Postgres爲特定數據庫管理的每個表的列表。
您還可以添加where table_schema = 'information_schema'
以僅查看信息架構中的表。
\dt information_schema.
從psql中,應該沒問題。
上市您的表使用:
SELECT table_name FROM information_schema.tables WHERE table_schema='public'
將您只建立清單表。
如何創建不具備訪問權限的表格? – huy 2013-03-06 09:07:30
這將只顯示公共模式中的表格。您可以在其他模式中創建表格。 – 2013-07-12 20:43:01
您也可以
select * from pg_tables where schemaname = 'information_schema'
使用在generall PG *表讓你看到一切都在分貝,不限制你的權限(如果你有機會到課程表)。
對於私人模式'xxx'
PostgreSQL中:
SELECT table_name FROM information_schema.tables
WHERE table_schema = 'xxx' AND table_type = 'BASE TABLE'
沒有table_type = 'BASE TABLE'
,你會列出表格和意見
的「\ 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)
如果你想快速和骯髒的單行查詢:
select * from information_schema.tables
您可以直接在查詢工具,而不必打開psql的運行它。
(其他職位提出很好的更具體的INFORMATION_SCHEMA查詢,但作爲一個牛逼,我發現這一個班輪查詢幫助我取得與該表握把)
謝謝,我只是嘗試:/ DT(星號)。 (星號)是不是有什麼不同? – littleK 2010-02-16 22:10:20
我不知道/ dt(星號)。(星號)的東西,對不起。我只是在postgres中運行select查詢,並列出了其中所有表的信息。 嘗試運行select語句(在您的空白數據庫)並查看它返回的內容。 – RodeoClown 2010-02-16 22:15:18
嘗試上述命令列出了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