COMPRESS
Description
The COMPRESS function compresses a string into binary data using the zlib compression algorithm. The compressed data can be decompressed back to the original string using the UNCOMPRESS function.
Syntax
COMPRESS(<str>)
Parameters
| Parameter | Description |
|---|---|
<str> | The string to be compressed. Type: VARCHAR |
Return Value
Returns VARCHAR type, which is the compressed binary data (not human-readable).
Special cases:
- If the parameter is NULL, returns NULL
- If the input is an empty string
'', returns an empty string''
Examples
- Basic usage: compression and decompression
SELECT uncompress(compress('hello'));
+-------------------------------+
| uncompress(compress('hello')) |
+-------------------------------+
| hello |
+-------------------------------+
- Empty string handling
SELECT compress('');
+--------------+
| compress('') |
+--------------+
| |
+--------------+
- NULL value handling
SELECT compress(NULL);
+----------------+
| compress(NULL) |
+----------------+
| NULL |
+----------------+
- UTF-8 character test
SELECT uncompress(compress('ṭṛì'));
+----------------------------------+
| uncompress(compress('ṭṛì')) |
+----------------------------------+
| ṭṛì |
+----------------------------------+