FORMAT_BYTES
Syntax
FORMAT_BYTES(count)
Description
FORMAT_BYTES() converts the count to a readable format and returns a string that contains the value and unit identifier. The result represents the number of bytes. The number of bytes in the string is rounded to two decimal places and has at least three significant digits. Numbers less than 1024 bytes are represented as integers and are not rounded. If count is NULL, FORMAT_BYTES() 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 1023 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
SELECT FORMAT_BYTES(128), FORMAT_BYTES(18446644073709551615);
+-------------------+------------------------------------+
| FORMAT_BYTES(128) | FORMAT_BYTES(18446644073709551615) |
+-------------------+------------------------------------+
| 128 bytes | 16.00 EiB |
+-------------------+------------------------------------+
1 row in set (0.001 sec)