Skip to content

Instantly share code, notes, and snippets.

@nburkley
Created August 25, 2016 09:56
Show Gist options
  • Save nburkley/2a2cb3d5b773095bf998f8f2c138171e to your computer and use it in GitHub Desktop.
Save nburkley/2a2cb3d5b773095bf998f8f2c138171e to your computer and use it in GitHub Desktop.
Get all tables with their number of rows in PostgreSQL
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';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment