Skip to main content

PARSE_DATA_SIZE

Description

The PARSE_DATA_SIZE function parses a string with storage units (such as "1.5GB") and converts it to a numeric value in bytes.

Syntax

PARSE_DATA_SIZE(<str>)

Parameters

ParameterDescription
<str>Data size string with unit (e.g., "100MB", "2.5GB"). Type: VARCHAR

Return Value

Returns BIGINT type, representing the numeric value converted to bytes.

Special cases:

  • Supported units (case-insensitive): B, kB, MB, GB, TB, PB, EB, ZB, YB
  • Units use base 1024 (e.g., 1kB = 1024B)
  • Supports decimals (e.g., "2.5MB")
  • If parameter format is invalid, returns error
  • If parameter is NULL, returns NULL

Supported Units Table:

UnitNameBytes
BBytes1
kBKilobytes1024
MBMegabytes1024²
GBGigabytes1024³
TBTerabytes1024⁴
PBPetabytes1024⁵
EBExabytes1024⁶

Examples

  1. Basic usage: Parse bytes
SELECT parse_data_size('1024B');
+--------------------------+
| parse_data_size('1024B') |
+--------------------------+
| 1024 |
+--------------------------+
  1. Parse kilobytes
SELECT parse_data_size('1kB');
+------------------------+
| parse_data_size('1kB') |
+------------------------+
| 1024 |
+------------------------+
  1. Parse megabytes with decimals
SELECT parse_data_size('2.5MB');
+--------------------------+
| parse_data_size('2.5MB') |
+--------------------------+
| 2621440 |
+--------------------------+
  1. Parse gigabytes
SELECT parse_data_size('1GB');
+------------------------+
| parse_data_size('1GB') |
+------------------------+
| 1073741824 |
+------------------------+
  1. Parse terabytes
SELECT parse_data_size('1TB');
+------------------------+
| parse_data_size('1TB') |
+------------------------+
| 1099511627776 |
+------------------------+
  1. Unsupported unit, error
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
  1. Input NULL
SELECT parse_data_size(NULL);
+-----------------------+
| parse_data_size(NULL) |
+-----------------------+
| NULL |
+-----------------------+

Keywords

PARSE_DATA_SIZE