Created
September 28, 2023 12:13
-
-
Save casperbrike/5bba377d83aabac6bbbe748a24019e42 to your computer and use it in GitHub Desktop.
Show list of tables and their rows count (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
WITH tbl AS | |
(SELECT table_schema, | |
TABLE_NAME | |
FROM information_schema.tables | |
WHERE TABLE_NAME not like 'pg_%' | |
AND table_schema in ('public')) | |
SELECT table_schema, | |
TABLE_NAME, | |
(xpath('/row/c/text()', query_to_xml(format('select count(*) as c from %I.%I', table_schema, TABLE_NAME), FALSE, TRUE, '')))[1]::text::int AS rows_n | |
FROM tbl | |
ORDER BY rows_n DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment