©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The COMPRESS SQL Function in MySQL and MariaDB - Compress string

COMPRESSSyntax:COMPRESS(String)
Return value:BINARY
Function type:Encryption & Compression
Function Description

The COMPRESS() function compresses "String" and returns the result as a binary string.

This function requires MySQL or MariaDB to be compiled with a compression library like zlib, otherwise the return value is always NULL.

Numeric values ​​are interpreted as a character string.

If "String" contains no characters, the function returns an empty string.

If the value of "String" is NULL, the COMPRESS() function returns NULL.


The compressed string can be uncompressed with UNCOMPRESS().

SQL Examples for the COMPRESS function

 1
 2
 3
 4
 5
 6
 7
 8
 9
10

SELECT hex(compress('Test Test Test Test Test'));
SELECT bit_length('Test Test Test Test Test');
SELECT bit_length(compress('Test Test Test Test Test'));

SELECT hex(compress(123123123));

SELECT compress('');
SELECT compress(null);

hex(compress('Test Test Test Test Test'))
varchar(80) BINARY
18000000789C0B492D2E5108C124006AD508A1
bit_length('Test Test Test Test Test')
bigint(11)
192
bit_length(compress('Test Test Test Test Test'))
bigint(11)
152
hex(compress(123123123))
varchar(44) BINARY
09000000789C3334323604230008CD01C3
compress('')
varchar(12) BINARY
 
compress(null)
varchar(12) BINARY
NULL
The examples were created with the MyWAY SQL manager: Download

How to use the COMPRESS() function in MySQL and MariaDB databases

MySQL and MariaDB provide the COMPRESS() function used to compress data using the zlib compression algorithm, where the function takes a string as input and returns the compressed data as a binary string.
To decompress the compressed data, the UNCOMPRESS() function can be used.

The COMPRESS() function can be used to reduce the disk space required to store large text or binary data, when transferring data over low-bandwidth networks to store in cache systems, or to improve query performance by compressing data. The effectiveness of the data compression depends on the properties of the data to be compressed.
COALESCECOERCIBILITYCOLLATIONCOMPRESSCONCATCONCAT_WSCONNECTION_ID

Further MySQL und MariaDB SQL Encryption & Compression

AES_DECRYPTAES_DECRYPT(String, Key)
More about AES_DECRYPT Function

AES_ENCRYPTAES_ENCRYPT(String, Key)
More about AES_ENCRYPT Function

DECODEDECODE(Binary string, Password)
More about DECODE Function

DES_DECRYPTDES_DECRYPT(Binary string [, Key])
More about DES_DECRYPT Function

DES_ENCRYPTDES_ENCRYPT(String [, Key])
More about DES_ENCRYPT Function

ENCODEENCODE(String, Password)
More about ENCODE Function

ENCRYPTENCRYPT(String [, Salt])
More about ENCRYPT Function

FROM_BASE64FROM_BASE64(String)
More about FROM_BASE64 Function

MD5MD5(String)
More about MD5 Function

OLD_PASSWORDOLD_PASSWORD(String)
More about OLD_PASSWORD Function

PASSWORDPASSWORD(String)
More about PASSWORD Function

RANDOM_BYTESRANDOM_BYTES(Length)
More about RANDOM_BYTES Function

SHASHA(String)
More about SHA Function

SHA1SHA1(String)
More about SHA1 Function

SHA2SHA2(String, Length)
More about SHA2 Function

TO_BASE64TO_BASE64(String)
More about TO_BASE64 Function

UNCOMPRESSUNCOMPRESS(Binary string)
More about UNCOMPRESS Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the COMPRESS SQL function: mysql.com and mariadb.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer