MariaDB UNCOMPRESS() Function
In MariaDB, UNCOMPRESS()
is a built-in function that decompresses strings compressed by the COMPRESS()
function.
MariaDB UNCOMPRESS()
Syntax
Here is the syntax of the MariaDB UNCOMPRESS()
function:
UNCOMPRESS(str_to_uncompress)
Parameters
str_to_uncompress
-
Required. A string to decompress.
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 'UNCOMPRESS'
.
Return value
The MariaDB UNCOMPRESS()
function decompresses the specified string str_to_uncompress
and returns the result as a binary string.
If the argument is NULL
, the MariaDB UNCOMPRESS()
function returns NULL
.
Check availability
The MariaDB UNCOMPRESS()
function requires MariaDB to be compiled with a compression library such as zlib. If MariaDB has not been compiled with such a compression library, UNCOMPRESS()
will not work, and it will return NULL
.
To determine whether the UNCOMPRESS()
function works correctly in the current MariaDB database server, use system variables have_compress
.
This statement returns whether the current MariaDB database server supports compression:
SELECT @@have_compress;
Output:
+-----------------+
| @@have_compress |
+-----------------+
| YES |
+-----------------+
If the server has access to the zlib compression library, the result is YES YES
, otherwise the result will be NO
.
MariaDB UNCOMPRESS()
Examples
Basic usage
Here’s a basic example:
SELECT UNCOMPRESS(COMPRESS('Hello'));
Output:
+-------------------------------+
| UNCOMPRESS(COMPRESS('Hello')) |
+-------------------------------+
| Hello |
+-------------------------------+
NULL
If the argument is NULL
, the MariaDB UNCOMPRESS()
function returns NULL
.
SELECT UNCOMPRESS(null);
Output:
+------------------+
| UNCOMPRESS(null) |
+------------------+
| NULL |
+------------------+
Conclusion
In MariaDB, UNCOMPRESS()
is a built-in function that decompresses strings compressed by the COMPRESS()
function.