MariaDB UNCOMPRESSED_LENGTH() Function

In MariaDB, UNCOMPRESSED_LENGTH() is a built-in function that returns the length in bytes of a string before being compressed by the COMPRESS() function.

MariaDB UNCOMPRESSED_LENGTH() Syntax

Here is the syntax of the MariaDB UNCOMPRESSED_LENGTH() function:

UNCOMPRESSED_LENGTH(compressed_str)

Parameters

compressed_str

Required. A string compressed using the COMPRESS() function.

If you provide the wrong number of parameters, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'UNCOMPRESSED_LENGTH'.

Return value

The MariaDB UNCOMPRESSED_LENGTH() function returns the length in bytes of the original string.

If the argument is NULL, the MariaDB UNCOMPRESSED_LENGTH() function returns NULL.

MariaDB UNCOMPRESSED_LENGTH() Examples

The following statement shows the basic usage of the MariaDB UNCOMPRESSED_LENGTH() function:

SELECT
  LENGTH(REPEAT('好', 500)),
  UNCOMPRESSED_LENGTH(COMPRESS(REPEAT('好', 500)))\G

Output:

                       LENGTH(REPEAT('好', 500)): 1500
UNCOMPRESSED_LENGTH(COMPRESS(REPEAT('好', 500))): 1500

This example uses the REPEAT() function to repeat '好' 500 times, and uses the LENGTH() function to obtain the byte length of the original string as 500, which is the same as the value returned by UNCOMPRESSED_LENGTH().

Conclusion

In MariaDB, UNCOMPRESSED_LENGTH() is a built-in function that returns the length in bytes of a string before being compressed by the COMPRESS() function.