Created
August 21, 2024 10:25
-
-
Save poacosta/7a4ed5066cf0d6ac583fe8555f84bf65 to your computer and use it in GitHub Desktop.
PostgreSQL: How to count rows in tables
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
DO $$ | |
DECLARE | |
r RECORD; | |
row_count BIGINT; | |
BEGIN | |
FOR r IN (SELECT relname FROM pg_stat_user_tables) LOOP | |
EXECUTE 'SELECT COUNT(*) FROM ' || quote_ident(r.relname) INTO row_count; | |
RAISE NOTICE 'Table: %, Row count: %', r.relname, row_count; | |
END LOOP; | |
END $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment