Contents
pg_size_bytes()
A function for converting human-readable data sizes into bytes
pg_size_bytes()
is a system function for converting human-readable data size values (e.g. 1KB
) into bytes (e.g. 1024
).
pg_size_bytes()
was added in PostgreSQL 9.6.
Usage
pg_size_bytes (text
) →bigint
Change history
- PostgreSQL 15
- able to convert sizes in petabytes (commit ca2e4472)
- PostgreSQL 9.6
- added (commit 53874c52)
Examples
Basic usage example for pg_size_bytes()
:
postgres=# SELECT pg_size_bytes('6137 MB'); pg_size_bytes --------------- 6435110912 (1 row)
Attempting to specifiy an invalid size unit:
postgres=# SELECT pg_size_bytes('1 YB'); ERROR: invalid size: "1 YB" DETAIL: Invalid size unit: "YB". HINT: Valid units are "bytes", "kB", "MB", "GB", and "TB".
References
- PostgreSQL documentation: Database Object Size Functions