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

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".

Categories

System function

See also

pg_size_pretty()