CREATE TYPE Examples | Teradata Database - Example: Creating a Structured UDT with 2 Attributes - Teradata Database

SQL Data Definition Language Syntax and Examples

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Teradata Database
Release Number
20.00
Publication Date
June 2025
Content Type
SQL Reference
Publication ID
B035-1144-200K
ft:locale
en-US
ft:lastEdition
2026-09-23
dita:mapPath
mbm1747160743883.ditamap
dita:ditavalPath
jlp1749501702948.ditaval
ft:sourceId
dita
dita:id
mdr1472255012272
lifecycle
latest

The following example creates a structured UDT named address that has two attributes defined with predefined data types: street and zip. This type is also defined with one constructor method (address (VARCHAR(20), CHAR(5)) and three instance methods (city() , state() , and in_state()).

Because no SPECIFIC method names are specified for the instance methods city() and in_state(CHAR(2)) in this example, the system autogenerates and registers the following TVMNameI SPECIFIC names for them in the SYSUDTLIB database:
  • ADDRESS_CITY_R on behalf of the city() method.
  • ADDRESS_IN_STATE_R on behalf of the in_state(CHAR(2)) method.
    CREATE TYPE address AS (
       street VARCHAR(20), 
       zip    CHARACTER(5) ) 
      NOT FINAL
     CONSTRUCTOR METHOD address( VARCHAR(20), CHARACTER(5) ) 
      RETURNS address
      SPECIFIC address_constructor_1
      SELF AS RESULT
      LANGUAGE C
      PARAMETER STYLE SQL
      DETERMINISTIC
      NO SQL,
     INSTANCE METHOD city() 
      RETURNS VARCHAR(20)
      LANGUAGE C
      PARAMETER STYLE SQL
      DETERMINISTIC
      NO SQL,
     METHOD state() 
      RETURNS CHARACTER(2) 
      SPECIFIC address_state
      RETURNS NULL ON NULL INPUT
      LANGUAGE C
      PARAMETER STYLE SQL
      DETERMINISTIC
      NO SQL,
     METHOD in_state(CHARACTER(2)) 
      RETURNS CHARACTER(1)
      LANGUAGE C
      PARAMETER STYLE SQL
      DETERMINISTIC
      NO SQL;