Calculate total row count from all tables

Moderator: NorbertKrupa

Post Reply
debfawn
Beginner
Beginner
Posts: 47
Joined: Tue Jan 29, 2013 2:30 pm

Calculate total row count from all tables

Post by debfawn » Wed Mar 06, 2013 2:14 pm

Hello,

My boss asked me to generate a daily report (sent via email) which shows the total number of rows for all tables in our DB. Is there an easy way to calculate this sum?

Thanks all!

pborne
Newbie
Newbie
Posts: 20
Joined: Mon Feb 18, 2013 1:37 am

Re: Calculate total row count from all tables

Post by pborne » Fri Mar 22, 2013 10:09 pm

Here's a starting point. It will show the total number of rows per node and schema, adding up the number of rows in the tables. Modify as needed.

Code: Select all

SELECT node_name,
	schema_name,
	sum(row_count)
FROM (
	SELECT node_name,
		projection_schema AS schema_name,
		anchor_table_name,
		projection_name,
		row_count,
		rank() OVER (PARTITION BY node_name, projection_schema, anchor_table_name ORDER BY projection_name) AS r
	FROM projection_storage ps
	) AS d
WHERE r = 1
GROUP BY 1, 2;

Post Reply

Return to “New to Vertica”