Syntax
FORMAT_BYTES(count)
Purpose
FORMAT_BYTES() converts the count value to a readable format and returns a string that consists of a value and a unit identifier. The result indicates the number of bytes. The number of bytes of the string is rounded to two decimal places and contains at least three significant digits. A number containing less than 1024 bytes is represented as an integer without rounding. If the count value is NULL, NULL is returned.
The unit identifier depends on the value of count in bytes. The following table describes the values and unit identifiers.
| Value | 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 or more | 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