Postgres 12.4 给出函数不存在的错误

Postgres 12.4 gives function does not exists error

我是 运行 postgres 12.4 中的以下查询:

SELECT (TABLE_SCHEMA || '"."' || TABLE_NAME) as table_name, 
       pg_size_pretty(pg_table_size(table_name)) as table_size,  
       pg_size_pretty(pg_indexes_size(table_name)) AS indexes_size, 
       pg_size_pretty(pg_total_relation_size(table_name)) as total_size 
from information_schema.TABLES nowait 
where TABLE_SCHEMA='myschema' 
order by pg_total_relation_size(table_name) desc;

我收到以下错误消息:

ERROR:  function pg_table_size(information_schema.sql_identifier) does not exist
LINE 1: ..."."' || TABLE_NAME) as table_name, pg_size_pretty(pg_table_s...
                                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

谁能告诉我我到底错过了什么?我还想提一下,完全相同的查询在 postgres 9.5 版中运行良好。我在 postgres 12.4 文档中也找不到任何内容。欢迎任何thoughts/suggestions。谢谢!

根据 Postgres --general 列表中的 thread

SELECT
    pg_size_pretty(pg_table_size(quote_ident(table_name))),
    pg_size_pretty(pg_indexes_size(quote_ident(table_name))) AS indexes_size,
    pg_size_pretty(pg_total_relation_size(quote_ident(table_name))) AS total_size
FROM
    information_schema.tables
WHERE
    table_schema = 'myschema'
;

您之前的查询从未使用过此查询:

(TABLE_SCHEMA || '"."' || TABLE_NAME) as table_name

它只是使用 table_name 列中的值,该列以前是 varchar,所以它在 pg_table_size() 中有效。现在列类型已更改,您需要使用 quote_ident() 来正确转换它。仅供参考,以上内容也适用于 9.5。