Last active
June 21, 2019 06:16
-
-
Save hbasria/bb45da34566946852f86 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
| SELECT | |
| pgClass.relname AS tableName, | |
| pgClass.reltuples AS rowCount | |
| FROM | |
| pg_class pgClass | |
| LEFT JOIN | |
| pg_namespace pgNamespace ON (pgNamespace.oid = pgClass.relnamespace) | |
| WHERE | |
| pgNamespace.nspname NOT IN ('pg_catalog', 'information_schema') AND | |
| pgClass.relkind='r' | |
| --OR-- | |
| create or replace function | |
| count_rows(schema text, tablename text) returns integer | |
| as | |
| $body$ | |
| declare | |
| result integer; | |
| query varchar; | |
| begin | |
| query := 'SELECT count(1) FROM ' || schema || '.' || tablename; | |
| execute query into result; | |
| return result; | |
| end; | |
| $body$ | |
| language plpgsql; | |
| -- | |
| select | |
| table_schema, | |
| table_name, | |
| count_rows(table_schema, table_name) | |
| from information_schema.tables | |
| where | |
| table_schema not in ('pg_catalog', 'information_schema') | |
| and table_type='BASE TABLE' | |
| order by 3 desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment