【问题标题】:Find number of rows on each table in a schema in postgres在 postgres 的模式中查找每个表上的行数
【发布时间】:2020-10-18 08:27:39
【问题描述】:

我在 Postgres 9.4 中运行它来获取特定模式中每个表的行数:

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 = 'pricing'

它在 Postgres 9.4 中有效,但在 Postgres 8.4 中我收到一条错误消息,提示格式函数不存在,postgres 8.4 中是否有类似的函数?

在 postgres 8.4 中我得到了这个:

函数格式(未知,information_schema.sql_identifier, information_schema.sql_identifier) 不存在

谢谢!

【问题讨论】:

    标签: postgresql function schema rowcount


    【解决方案1】:

    所有模式中的所有表行数

    SELECT relname, n_tup_ins - n_tup_del as rowcount FROM pg_stat_all_tables;
    

    给定模式中的所有表行计数

    SELECT 
      nspname AS schemaname,relname,reltuples
    FROM pg_class C
    LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
    WHERE 
      nspname IN ('schema_name') AND
      relkind='r' 
    ORDER BY reltuples DESC;
    

    【讨论】:

    • 我认为这提供了估计,不是吗?
    猜你喜欢
    • 2023-03-17
    • 2022-01-14
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    • 2018-10-19
    • 1970-01-01
    相关资源
    最近更新 更多