Last active
February 19, 2022 03:20
-
-
Save PostgreSqlStan/0737b8d2f1592d2eac68d0124d509610 to your computer and use it in GitHub Desktop.
PostgreSQL view to list tables/views from all schemas
This file contains 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
-- view: ls (tested on postgres 14.1) | |
CREATE OR REPLACE VIEW ls AS | |
SELECT | |
N.nspname AS "schema", | |
relname AS "relation", | |
CASE c.relkind | |
WHEN 'f' THEN 'fdw table' | |
WHEN 'r' THEN 'table' | |
WHEN 'v' THEN 'view' | |
WHEN 'm' THEN 'm view' END AS "type", | |
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total size", | |
obj_description(C.oid) AS "comment" | |
FROM pg_class C | |
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) | |
WHERE nspname NOT IN ('pg_catalog', 'information_schema') | |
AND nspname !~ '^pg_toast' | |
ORDER BY 1, 2; | |
COMMENT ON VIEW ls IS 'list relations in all schemas'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment