如何获取PostgreSQL 9.5中特定模式中存在的所有表的表行计数?我想要的结果为table_name | row_count。如何使用查询做到这一点?
这可以通过一些XML魔术来完成:
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 = 'public'