17.10 - VARBYTE - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)

C Data Type and Macro Definition

typedef struct VARBYTE
{
    int   length;            /* length of string */
    BYTE  bytes[1];          /* bytes - size must be adjusted */
} VARBYTE;
#define VARBYTE_M(len) struct { int length; BYTE bytes[len]; }

Usage

Use the VARBYTE structure for reference to an existing VARBYTE.

Use the VARBYTE_M macro to define your own VARBYTE of specific length. For example, to define a VARBYTE of length 30, use the macro like this:

VARBYTE_M(30) myvbstr;

If the function result type is variable length byte data, then the result argument points to a data area containing a VARBYTE structure with a bytes field reserved to the maximum defined by the RETURNS clause in the CREATE FUNCTION statement.

Here is an example using VARBYTE in a UDF definition and C function declaration.

SQL Function Definition Equivalent C Function Declaration
CREATE FUNCTION F1 (
  A VARBYTE(30) )
RETURNS VARBYTE(12)
 ...;
void f1( VARBYTE *a,
         VARBYTE *result,
   ... )
{  ... }