I want to write a query that counts every object in the database. I'm aware that you can query for statistics, but I want to know how to write this general type of query in case I need to do it again.
I have the results of this query, which gives every table name in the DB:
SELECT table_name
FROM information_schema.tables
WHERE table_schema='public'
AND table_type='BASE TABLE'
The results look something like this:
table_name
----------
queue_classic_jobs
activities
attachments
comments
csv_files
I want to do a count(*)
on each table for each resulting row:
table_name | row_count
----------------------------------
queue_classic_jobs 6
activities 2
attachments 4
comments 8
csv_files 10
and then sum the row_count column. What should my query look like?