Postgres: row count for all tables in that schema

 select table_schema, table_name,

       (xpath('/row/count/text()', query_to_xml('select count(*) from '||format('%I.%I', table_schema, table_name), true, true, '')))[1]::text::int as row_count
from information_schema.tables
where table_schema = 'tailoring'
order by table_name asc



or


 with tbl as 
   (SELECT table_schema,table_name 
    FROM information_schema.tables   
    where table_name not like 'pg_%' and table_schema in ('cfadmin','ctlgadmin','ctlgadmin2','cmsadmin','cmtadmin','gcpcustomjobs','grpadmin','invadmin','ordadmin','fivertranuser','cfaudit'))   
select table_schema, table_name, 
       (xpath('/row/c/text()', query_to_xml(format('select count(*) as c from %I.%I', table_schema, table_name), false, true, '')))[1]::text::int as rows_n 
from tbl 
ORDER BY 3 DESC;


Comments

Popular posts from this blog

Oracle: To clean up WRI$_ADV_OBJECTS