compress_nvarchar() function

The compress_nvarchar() function compresses nvarchar data by using the public source zlib software library. The zlib library uses the DEFLATE compression algorithm, a variation of Lempel-Ziv 1977 (LZ77).

For details about the compression process, see compress() function and decompress() function.

Important: To process nvarchar values, you should use the compress_nvarchar() function instead of the compress() function and the decompress_nvarchar() function instead of the decompress() function. The compress() function remains for compatibility with earlier versions and results, but tables and views that store compress('NVARCHAR') function values might encounter problems during loads and GENERATE STATISTICS operations.

Syntax

The compress_nvarchar() function has the following syntax:
nvarchar = compress_nvarchar(nvarchar input[, int level]);

The input value specifies the nvarchar value to compress.

The level value specifies the compression level to use. 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_nvarchar('1234567890'::nvarchar(11));
  COMPRESS_NVARCHAR
 -------------------
  x�3426153·°4
  (1 row)