compress() function
The compress() function compresses a varchar or nvarchar value by using the public source zlib software library. The zlib library uses the DEFLATE compression algorithm, a variation of Lempel-Ziv 1977 (LZ77).
Compression is the process of encoding data so that it uses fewer bits. For example, compression replaces instances of contiguous, repeated characters with a single character and a count. You must decompress compressed data before you can use it.
Syntax
varchar = compress(varchar input[, int level]);
nvarchar = compress(nvarchar input[, int level]);
The input value specifies the
varchar or nvarchar value to
compress.
The level value specifies the
compression level that is used.
It can be 0 - 9, with 0 indicating the least
compression and 9 indicating the most compression.
The default is
6. Increasing the compression level increases the
processing time.
Returns
The function returns the compressed value.
Example
select compress('1234567890');
COMPRESS
--------------
x3426153·˚4
(1 row)