15.00 - CREATE FUNCTION and Algorithmic Compression of UDT Columns - Teradata Database

Teradata Database SQL Data Definition Language Detailed Topics

prodname
Teradata Database
vrm_release
15.00
category
Programming Reference
featnum
B035-1184-015K

CREATE FUNCTION and Algorithmic Compression of UDT Columns

You must specify either FOR COMPRESS or FOR DECOMPRESS, respectively, when you create an SQL function definition for an external UDF that is to be used to either compress or decompress BYTE, VARBYTE, CHARACTER, VARCHAR, GRAPHIC, Period, distinct UDT (including ARRAY/VARRAY), BLOB, CLOB, XML, Geospatial, distinct BLOB‑based UDT, distinct CLOB‑based UDT, or distinct XML‑based UDT column values algorithmically. If you do not specify these options in the function definition, it cannot be used to algorithmically compress or decompress column values.

The following rules apply to creating UDFs to implement algorithmic compression and decompression of UDT data.

  • The compression and decompression routines you code can be either external scalar UDFs or embedded services scalar UDFs.
  • Embedded services UDFs that are used for algorithmic compression are for Internal UDT types such as Period, ARRAY, VARRAY, and Geospatial. They cannot be used for structured UDTs.

    External UDFs are mainly used for distinct UDTs.

  • All distinct UDT types are supported for algorithmic compression.
  • Structured UDT types are supported for algorithmic compression.

  • The compress UDF must have the following signature.
  • There must be a single input parameter that can be any of the supported UDT data types.
  • The parameter data type of the compression function must match the data type of the UDT column exactly.
  • The UDT parameter data type of the compression function must match the return data type of the decompression function exactly.
  • The return data type must be VARBYTE(n).
  • The compression function VARBYTE(n) return length n must match the length of the decompression function VARBYTE(n) parameter exactly.
  • A decompression UDF must have the following signature.
  • There must be a single input parameter whose data type must be VARBYTE(n).
  • The return data type of the decompression function must match the data type of the UDT column exactly.
  • The return data type of the decompression function must match the UDT parameter data type of the compression function exactly.
  • The decompression function VARBYTE(n) return length n must match the length of the compression function VARBYTE(n) parameter exactly.
  • The output of the decompress UDF must be one of the supported UDT data types.
  • Accessing or writing an algorithmically‑compressed column implicitly encapsulates the column reference with the appropriate routine.

    See “Compressing Column Values Using Only Multi-Value Compression” on page 548 for additional information about the TD_LZ_COMPRESS and TD_LZ_DECOMPRESS UDFs.