从 pg_size_pretty 恢复值,转换为 bigint

ati*_*ruz 3 sql postgresql

如何恢复到pg_size_prettyPostgreSQL 中生成的原始值。

SELECT
 c.relname
,pg_size_pretty (pg_relation_size (c.oid))
FROM pg_class c
ORDER BY c.relpages DESC
LIMIT 1;

RESULT:
relname | pg_size_pretty
------------------------
tabla   | 928 MB
Run Code Online (Sandbox Code Playgroud)

我需要:928 MB > 973078528

Pet*_*ier 5

此内置函数pg_size_bytes(text)从 9.6 开始可用。

postgres=# --
select
    pg_size_pretty(973078528::bigint),
    pg_size_bytes('928 MB'),
    (pg_size_bytes('928 MB') > 973078528)::text as "is_bigger"
;
 pg_size_pretty | pg_size_bytes | is_bigger
----------------+---------------+-----------
 928 MB         |     973078528 | false
(1 row)

postgres=#
Run Code Online (Sandbox Code Playgroud)

在 db<>fiddle 上尝试一下