List tables by the number of rows in Redshift

This query returns list of tables in a database with their number of rows.

Query

select tab.table_schema,
       tab.table_name,
       tinf.tbl_rows as rows
from svv_tables tab
join svv_table_info tinf
          on tab.table_schema = tinf.schema
          and tab.table_name = tinf.table
where tab.table_type = 'BASE TABLE'
      and tab.table_schema not in('pg_catalog','information_schema')
      and tinf.tbl_rows > 1
order by tinf.tbl_rows desc;

Columns

  • table_schema - schema name
  • table_name - table name
  • rows - number of rows in a table

Rows

  • One row represents one table
  • Scope of rows: all tables in a database having more than one row
  • Ordered by number of rows descending, from largest to smallest (in terms of number of rows)

Sample results

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
0
There are no comments. Click here to write the first comment.