COMPRESS( )

This MySQL function returns a given string after compressing it.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

COMPRESS(string)

Explanation

This function returns a given string after compressing it. It requires MySQL to have been compiled with a compression library (i.e., zlib). If it wasn't, a NULL value will be returned. This statement is available as of version 4.1 of MySQL.

Examples

UPDATE students_records
SET personal_essay =
(SELECT COMPRESS(essay)
 FROM student_applications
 WHERE applicant_id = '7382') AS derived1
WHERE student_id = '433302000';

If you want to store a value that was compressed with this function, it's best to store it in a BLOB column since the results are binary. Use UNCOMPRESS() to uncompress a string that was compressed with this function.