Declaration
FORMAT_BYTES(count)
Description
The FORMAT_BYTES() function converts count into a readable format and returns a string consisting of the value and a unit identifier, representing the number of bytes. The resulting string rounds the number of bytes to two decimal places and contains at least three significant digits. Numbers less than 1024 bytes are represented as integers without rounding. If count is NULL, the function returns NULL.
The unit identifier depends on the size of the byte count parameter, as shown in the following table.
Parameter Value |
Result unit |
Unit Identifier |
|---|---|---|
| Up to 1,023 bytes | bytes | bytes |
| Up to 10242− 1 bytes | kibibytes | KiB |
| Up to 10243− 1 bytes | mebibytes | MiB |
| Up to 10244− 1 bytes | gibibytes | GiB |
| Up to 10245− 1 bytes | tebibytes | TiB |
| Up to 10246− 1 bytes | pebibytes | PiB |
| 10246 bytes and above | exbibytes | EiB |
Examples
obclient> SELECT FORMAT_BYTES(128), FORMAT_BYTES(18446644073709551615);
+-------------------+------------------------------------+
| FORMAT_BYTES(128) | FORMAT_BYTES(18446644073709551615) |
+-------------------+------------------------------------+
| 128 bytes | 16.00 EiB |
+-------------------+------------------------------------+
1 row in set