我有大約 90 個模式的資料庫。在每個模式中,我轉到“Materialized Views”并轉到一個名為“product_visitor_view”的視圖,然后創建一個 SELECT 腳本,然后撰寫該腳本并運行它并查看結果:
SELECT priority, count(*)
FROM ag_modem_01.product_visitor_view
group by priority;
但是,我不能為所有 90 個模式執行此操作。有沒有一種方法可以對所有模式執行此操作,結果將顯示在頁面中的每個模式,我該怎么做?
先感謝您。
uj5u.com熱心網友回復:
您可以使用以下查詢為每個模式準備 SQL。這個想法是代替手動撰寫所有查詢,您可以使用系統表pg_matviews包含有關物化視圖的資訊。獲得串列后,只需在所有行之間進行聯合。
select
string_agg('select '''||schemaname||''' as schema,priority,count(*) from '||schemaname||'.'||matviewname
||' group by priority '||chr(10),' Union All '||chr(10)
)
from pg_matviews
where matviewname='product_visitor_view'
and ispopulated=true; -- to filter out Views which has not been populated
獲取此查詢的輸出并在 Querytool 中運行它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/475225.html
標籤:sql PostgreSQL pgadmin pgadmin-4
上一篇:在case陳述句中難以給出別名
