Created
May 8, 2020 15:26
-
-
Save elhoyos/9193ba59cb8cf93296cb3181bb8f7130 to your computer and use it in GitHub Desktop.
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
-- Count the number of rows for all tables in a schema | |
-- From: https://stackoverflow.com/a/38684225/638425 | |
select table_schema, | |
table_name, | |
(xpath('/row/cnt/text()', xml_count))[1]::text::bigint 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' --<< change here for the schema you want | |
) t; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment