Created
January 29, 2026 20:53
-
-
Save goors/34ecb0ee78ff75ad63a2ad7776002862 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
| --- PostgreSQL: Row Count for All Tables in a Schema | |
| DO $$ | |
| DECLARE | |
| r RECORD; | |
| cnt BIGINT; | |
| BEGIN | |
| FOR r IN | |
| SELECT tablename | |
| FROM pg_tables | |
| WHERE schemaname = 'table_name' | |
| LOOP | |
| EXECUTE format('SELECT count(*) FROM table_name.%I', r.tablename) | |
| INTO cnt; | |
| RAISE NOTICE '%: % rows', r.tablename, cnt; | |
| END LOOP; | |
| END $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment