15.00 - LZCOMP - Teradata Database

Teradata Database SQL Functions, Operators, Expressions, and Predicates

Product
Teradata Database
Release Number
15.00
Content Type
Programming Reference
Publication ID
B035-1145-015K
Language
English (United States)
Last Update
2018-09-24

LZCOMP

Purpose  

Compresses the specified Unicode character data using the Lempel-Ziv algorithm.

Syntax  

where:

 

Syntax element…

Specifies…

TD_SYSFNLIB

the name of the database where the function is located.

Unicode_string

a Unicode character string or string expression.

Note: This function takes no arguments when used as part of the COMPRESS USING or DECOMPRESS USING phrases. For more information about the COMPRESS/DECOMPRESS phrase, see SQL Data Types and Literals.

ANSI Compliance

This is a Teradata extension to the ANSI SQL:2011 standard.

Argument Type and Rules

Expressions passed to this function must have a data type of VARCHAR(n) CHARACTER SET UNICODE, where the maximum supported size (n) is 32000. You can also pass arguments with data types that can be converted to VARCHAR(32000) CHARACTER SET UNICODE using the implicit data type conversion rules that apply to UDFs. For example, LZCOMP(CHAR) is allowed because it can be implicitly converted to LZCOMP(VARCHAR).

Note: The UDF implicit type conversion rules are more restrictive than the implicit type conversion rules normally used by Teradata Database. If an argument cannot be converted to VARCHAR following the UDF implicit conversion rules, it must be explicitly cast.

For details, see “Compatible Types” in SQL External Routine Programming.

The input to this function must be Unicode character data.

If you specify NULL as input, the function returns NULL.

Result Type

The result data type is VARBYTE(64000).

Usage Notes

Uncompressed character data in Teradata Database requires 2 bytes per character when storing Unicode data. LZCOMP takes Unicode character input, compresses it using the Lempel-Ziv algorithm, and returns the compressed result.

See http://zlib.net for information about the compression algorithm used by LZCOMP.

LZCOMP provides good compression results for long Unicode strings, but might not be as effective for short strings. It can also provide good results for medium strings that have many repeating characters.

For a detailed comparison between the Teradata-supplied compression functions and guidelines for choosing a compression function, see Database Administration.

Although you can call the function directly, LZCOMP is normally used with algorithmic compression (ALC) to compress table columns. If LZCOMP is used with ALC, nulls are also compressed if those columns are nullable.

For more information about ALC, see “COMPRESS and DECOMPRESS Phrases” in SQL Data Types and Literals.

Uncompressing Data Compressed with LZCOMP

To uncompress Unicode data that was compressed using LZCOMP, use the LZDECOMP function. See “LZDECOMP” on page 540.

Example

In this example, the Unicode values in the Description column are compressed using the LZCOMP function with ALC. The LZDECOMP function uncompresses the previously compressed values.

   CREATE MULTISET TABLE Pendants
      (ItemNo INTEGER,
       Gem CHAR(10) UPPERCASE CHARACTER SET UNICODE,
       Description VARCHAR(1000) CHARACTER SET UNICODE
          COMPRESS USING TD_SYSFNLIB.LZCOMP
          DECOMPRESS USING TD_SYSFNLIB.LZDECOMP);

Example

Given the following table definition:

   CREATE TABLE Pendants
      (ItemNo INTEGER,
       Description VARCHAR(100) CHARACTER SET UNICODE);

The following query returns the compressed values of the Description column.

   SELECT TD_SYSFNLIB.LZCOMP(Pendants.Description);