Last active
November 1, 2023 22:32
-
-
Save snelson82/a072eabd1158f39511df29e75deadd73 to your computer and use it in GitHub Desktop.
PostgreSQL - All tables and record count
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
SELECT | |
table_schema, | |
table_name, | |
(xpath('/row/cnt/text()', xml_count))[1]::text::int AS row_count | |
FROM ( | |
SELECT | |
table_name, | |
table_schema, | |
query_to_xml(format('select count(*) as cnt from %I.%I', table_schema, table_name), FALSE, TRUE, '') AS xml_count | |
FROM | |
information_schema.tables | |
WHERE | |
table_schema = 'public') t; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment