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