HELP CAST Examples | Teradata Vantage - 17.05 - HELP CAST Examples - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Definition Language Syntax and Examples

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Release Date
January 2021
Content Type
Programming Reference
Publication ID
B035-1144-175K
Language
English (United States)

Example: Source Castings Only

The following example reports the source castings for the UDT named euro:

     HELP CAST SYSUDTLIB.euro SOURCE;
Source    Target         Cast Routine         As Assignment
---------------------------------------------------------------------
euro      DECIMAL(10,2)  System                   YES
euro      us_dollar      EurotoUS                 NO

Example: Target Castings Only

The following example reports the target castings for the UDT named euro:

     HELP CAST SYSUDTLIB.euro TARGET;
Source         Target         Cast Routine           As Assignment
----------------------------------------------------------------------
DECIMAL(10,2)  euro           System                     YES
us_dollar      euro           UstoEuro                   YES

Example: All Castings for a UDT That Has Multiple Casting Pairs

The following example shows the output of HELP CAST euro with no options:

     HELP CAST euro;
Source         Target         Cast Routine           As Assignment
----------------------------------------------------------------------
euro           DECIMAL(10,2)  System                     YES
DECIMAL(10,2)  euro           System                     YES
us_dollar      euro           UstoEuro                   YES
euro           us_dollar      EurotoUS                   NO

Note the following things about this report:

  • Because this UDT has two casting pairs (euro:DECIMAL and euro:us_dollar ), there are four rows in the report.
  • The euro:DECIMAL casting pair was system-generated (its cast routine in both cases is named System), while the euro:us_dollar casting pair was user-defined.
  • There is no implicit casting for the euro:us_dollar cast because it was not defined with the AS ASSIGNMENT option.

Example: All Castings For A UDT That Has A Single Casting Pair

The following example reports both the source and target castings for the UDT named address:

     HELP CAST address;
Source       Target           Cast Routine           As Assignment
----------------------------------------------------------------------
address      VARCHAR(80)      address_2_char             YES
VARCHAR(80)  address          char_2_address             YES

Note the following things about this report:

  • The castings from address to VARCHAR(80) and from VARCHAR(80) to address are complementary to one another.
  • Both casting routines are user-defined, because neither is named System.
  • This UDT has only one casting pair defined for it, neither of which is named System, which suggests that it is probably a structured type.

    Castings for structured types are not system-generated, while the system generates default casts for distinct types. Because it is also possible to drop the system-generated casts for a distinct UDT and replace them with user-defined casts, the inference that the casting reported in this example is for a structured UDT cannot be made with certainty. See CREATE CAST and REPLACE CAST.