如何获取PostgreSQL 9.5中特定模式中存在的所有表的表行数? [英] how to get the table row count of all the tables present in particular schema in postgresql 9.5?

查看:96
本文介绍了如何获取PostgreSQL 9.5中特定模式中存在的所有表的表行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取Postgresql 9.5中特定模式中存在的所有表的表行计数?我想将结果作为table_name | row_count。

how to get the table row count of all the tables present in particular schema in postgresql 9.5? I would like to have the result as table_name | row_count. How this can be done using query?

推荐答案

这可以通过一些XML魔术来完成:

This can be done with some XML magic:

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'

这篇关于如何获取PostgreSQL 9.5中特定模式中存在的所有表的表行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆