Created
February 27, 2025 18:58
-
-
Save dhermes/cd8a07559ce4c5d7ab0338ebd666893e to your computer and use it in GitHub Desktop.
[2025-02-27] Building a dependency graph for materialized view(s) (PostgreSQL)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT DISTINCT | |
r.ev_class::regclass AS materialized_view, | |
n.nspname AS schema_name, | |
c.relname AS object_name, | |
CASE c.relkind | |
WHEN 'r' THEN 'Table' | |
WHEN 'v' THEN 'View' | |
WHEN 'm' THEN 'Materialized View' | |
WHEN 'f' THEN 'Foreign Table' | |
WHEN 'p' THEN 'Partitioned Table' | |
ELSE '<Unknown>' | |
END AS object_type | |
FROM | |
pg_catalog.pg_depend AS d | |
INNER JOIN pg_catalog.pg_rewrite AS r ON r.oid = d.objid | |
INNER JOIN pg_catalog.pg_class AS c ON c.oid = d.refobjid | |
INNER JOIN pg_catalog.pg_namespace AS n ON n.oid =c.relnamespace | |
WHERE | |
r.ev_class IN ( | |
'foo'::regclass, | |
'bar'::regclass, | |
'baz'::regclass | |
-- ... | |
) | |
AND d.refobjid <> r.ev_class | |
ORDER BY materialized_view, schema_name, object_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment