The PARSE_DATA_SIZE function parses a string with storage units (such as “1.5GB”) and converts it to a numeric value in bytes.
PARSE_DATA_SIZE(<str>)
| Parameter | Description |
|---|---|
<str> | Data size string with unit (e.g., “100MB”, “2.5GB”). Type: VARCHAR |
Returns LARGEINT type, representing the numeric value converted to bytes.
Special cases:
Supported Units Table:
| Unit | Name | Bytes |
|---|---|---|
| B | Bytes | 1 |
| kB | Kilobytes | 1024 |
| MB | Megabytes | 1024² |
| GB | Gigabytes | 1024³ |
| TB | Terabytes | 1024⁴ |
| PB | Petabytes | 1024⁵ |
| EB | Exabytes | 1024⁶ |
SELECT parse_data_size('1024B');
+--------------------------+ | parse_data_size('1024B') | +--------------------------+ | 1024 | +--------------------------+
SELECT parse_data_size('1kB');
+------------------------+ | parse_data_size('1kB') | +------------------------+ | 1024 | +------------------------+
SELECT parse_data_size('2.5MB');
+--------------------------+ | parse_data_size('2.5MB') | +--------------------------+ | 2621440 | +--------------------------+
SELECT parse_data_size('1GB');
+------------------------+ | parse_data_size('1GB') | +------------------------+ | 1073741824 | +------------------------+
SELECT parse_data_size('1TB');
+------------------------+ | parse_data_size('1TB') | +------------------------+ | 1099511627776 | +------------------------+
SELECT parse_data_size('1iB');
ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.3)[INVALID_ARGUMENT]Invalid Input argument "1iB" of function parse_data_size
SELECT parse_data_size(NULL);
+-----------------------+ | parse_data_size(NULL) | +-----------------------+ | NULL | +-----------------------+
PARSE_DATA_SIZE