Skip to main content

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 ValueResult UnitUnit Identifier
Up to 1023 bytesbytesbytes
Up to 10242− 1 byteskibibytesKiB
Up to 10243− 1 bytesmebibytesMiB
Up to 10244− 1 bytesgibibytesGiB
Up to 10245− 1 bytestebibytesTiB
Up to 10246− 1 bytespebibytesPiB
10246 bytes and aboveexbibytesEiB

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)