TIME WITH TIME ZONE - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
qwr1571437338192.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™

C Data Type Definition

typedef struct ANSI_Time_WZone
{
    DECIMAL4 seconds;
    BYTEINT  hour;
    BYTEINT  minute;
    BYTEINT  zone_hour;
    BYTEINT  zone_minutes;
} ANSI_Time_WZone;

Usage

The seconds member is laid out as a DECIMAL(8,6) numeric field, which can represent up to two digits of whole seconds and six digits of fractional seconds.

The range of values defined for the SQL TIME WITH TIME ZONE type applies to the input arguments and return argument of a function. A value outside the valid range of values produces an error.

All TIME WITH TIME ZONE values passed to a UDF are in Universal Coordinated Time (UTC), and all TIME WITH TIME ZONE values that are returned from a UDF must be in UTC.

The TIME WITH TIME ZONE type has time zone fields, zone_hour and zone_minute, that have an internal form and an external form. When input arguments of this type are passed to a UDF, the values must be in internal form. Similarly, return arguments with this type must be in internal form.

To modify the time zone fields of the TIME WITH TIME ZONE type, use the following macros in the sqltypes_td.h file to convert between the internal and external representation of the time zone fields of ANSI_Time_Wzone and ANSI_TimeStamp_Wzone.

  • TIMEZONE_INTERNAL_TO_EXTERNAL(i,s,h,m)

    where:

    Input Parameter Description
    i a pointer to an ANSI_Time_Wzone or a pointer to an ANSI_TimeStamp_Wzone.
    s a BYTEINT value to store the sign of i.
    h a BYTEINT value to store the hour offset of i.
    m a BYTEINT value to store the minute offset of i.
  • TIMEZONE_EXTERNAL_TO_INTERNAL(s,h,m,i)

    where:

    Input Parameter Description
    s a BYTEINT value to set the sign for i.
    h a BYTEINT value to set the hour offset for i.
    m a BYTEINT value to set the minute offset for i.
    i a pointer to an ANSI_Time_Wzone or a pointer to an ANSI_TimeStamp_Wzone.
The external representation of the time zone fields consists of 3 values: a sign, an hour offset, and a minute offset where:
  • The sign is a BYTEINT value which is 0 if the offsets are negative and 1 if the offsets are positive.
  • The external form for the hour offset is a BYTEINT value between 0 and 14 inclusive prior and post conversion. This represents the hour offset between UTC and the given time zone.
  • The external form for the minute offset is a BYTEINT value between 0 and 59 inclusive prior and post conversion. This represents the minute offset between UTC and the given time zone.

The largest value for negative offsets is -12:59. The largest value for positive offsets is +14:00.

This representation results in two representations of UTC, that is +00:00 and -00:00. This mirrors the internal representation which uses both representations for display purposes.

For details on the TIME WITH TIME ZONE type, see Teradata Vantage™ - Data Types and Literals, B035-1143.

Here is an example of TIME WITH TIME ZONE in a UDF definition and C function declaration.

SQL Function Definition Equivalent C Function Declaration
CREATE FUNCTION F1 (
  A TIME WITH TIME ZONE)
RETURNS TIME WITH TIME ZONE
 ...;
void f1( ANSI_Time_WZone *a,
         ANSI_Time_WZone *result,
   ... )
{  ... }