Teradata中有一个系统表,我可以在其中找到列类型的全名?

时间:2016-08-24 23:06:16

标签: teradata

我正在使用Teradata 14.10而我没有找到一个系统表,其中包含表ColumnTypesDBC.Columns <字段DBC.ColumnsVX中使用的数据类型的全名/ p>

我在forum找到了从ColumnTypes代码到其全名的映射,但我不想手动进行映射。

3 个答案:

答案 0 :(得分:2)

没有官方表格,但可以通过Data Dictionary manual中提供的映射轻松创建(这是DevEx链接中的列表从中复制的位置)。

但我更喜欢使用简单的SQL UDF进行映射,因为可能值的列表非常稳定(在新的TD版本中,您可能需要插入新行或添加新的WHEN条件):

REPLACE FUNCTION Datatype
 (
  ColumnType CHAR(2)
 )
RETURNS VARCHAR(60)
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
SQL SECURITY DEFINER
COLLATION INVOKER
INLINE TYPE 1
RETURN 
  CASE ColumnType
    WHEN 'BF' THEN 'BYTE'
    WHEN 'BV' THEN 'VARBYTE'
    WHEN 'CF' THEN 'CHAR'
    WHEN 'CV' THEN 'VARCHAR'
    WHEN 'D ' THEN 'DECIMAL'
    WHEN 'DA' THEN 'DATE'
    WHEN 'F ' THEN 'FLOAT'
    WHEN 'I1' THEN 'BYTEINT'
    WHEN 'I2' THEN 'SMALLINT'
    WHEN 'I8' THEN 'BIGINT'
    WHEN 'I ' THEN 'INTEGER'
    WHEN 'AT' THEN 'TIME'
    WHEN 'TS' THEN 'TIMESTAMP'
    WHEN 'TZ' THEN 'TIME WITH TIME ZONE'
    WHEN 'SZ' THEN 'TIMESTAMP WITH TIME ZONE'
    WHEN 'YR' THEN 'INTERVAL YEAR'
    WHEN 'YM' THEN 'INTERVAL YEAR TO MONTH'
    WHEN 'MO' THEN 'INTERVAL MONTH'
    WHEN 'DY' THEN 'INTERVAL DAY'
    WHEN 'DH' THEN 'INTERVAL DAY TO HOUR'
    WHEN 'DM' THEN 'INTERVAL DAY TO MINUTE'
    WHEN 'DS' THEN 'INTERVAL DAY TO SECOND'
    WHEN 'HR' THEN 'INTERVAL HOUR'
    WHEN 'HM' THEN 'INTERVAL HOUR TO MINUTE'
    WHEN 'HS' THEN 'INTERVAL HOUR TO SECOND'
    WHEN 'MI' THEN 'INTERVAL MINUTE'
    WHEN 'MS' THEN 'INTERVAL MINUTE TO SECOND'
    WHEN 'SC' THEN 'INTERVAL SECOND'
    WHEN 'BO' THEN 'BLOB'
    WHEN 'CO' THEN 'CLOB'
    WHEN 'PD' THEN 'PERIOD(DATE)'     
    WHEN 'PM' THEN 'PERIOD(TIMESTAMP WITH TIME ZONE)'
    WHEN 'PS' THEN 'PERIOD(TIMESTAMP)'
    WHEN 'PT' THEN 'PERIOD(TIME)'
    WHEN 'PZ' THEN 'PERIOD(TIME WITH TIME ZONE)'
    WHEN 'UT' THEN 'User Defined Datatype'
    WHEN '++' THEN 'TD_ANYTYPE'
    WHEN 'N'  THEN 'NUMBER'
    WHEN 'A1' THEN 'ARRAY'
    WHEN 'AN' THEN 'ARRAY (multidimensional'
    WHEN 'JN' THEN 'JSON'
    WHEN 'VA' THEN 'TD_VALIST'
    WHEN 'XM' THEN 'XML'
    ELSE '<Unknown> ' 
  END;

您也可以使用此SQL-UDF来获取完整数据类型(我没有添加新的15.10 JSON - 变体BSON&amp; UBJSON,但是):

/**********
Returns the datatype of a column as a literal

20111012 initial version - Dieter Noeth
20131010 added TD14.10 ARRAY datatypes - dn
20140812 added TD15 JSON / TD_VALIST datatype - dn
**********/
REPLACE FUNCTION DataTypeString 
 (
  ColumnType CHAR(2),
  ColumnLength INT,
  DecimalTotalDigits SMALLINT,
  DecimalFractionalDigits SMALLINT,
  CharType SMALLINT,
  ColumnUDTName VARCHAR(128) CHARACTER SET UNICODE
 )
RETURNS VARCHAR(60)
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
SQL SECURITY DEFINER
COLLATION INVOKER
INLINE TYPE 1
RETURN 
  CASE ColumnType
    WHEN 'BF' THEN 'BYTE('            || TRIM(ColumnLength (FORMAT '-(9)9')) || ')'
    WHEN 'BV' THEN 'VARBYTE('         || TRIM(ColumnLength (FORMAT 'Z(9)9')) || ')'
    WHEN 'CF' THEN 'CHAR('            || TRIM(ColumnLength (FORMAT 'Z(9)9')) || ')'
    WHEN 'CV' THEN 'VARCHAR('         || TRIM(ColumnLength (FORMAT 'Z(9)9')) || ')'
    WHEN 'D ' THEN 'DECIMAL('         || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ','
                                      || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'DA' THEN 'DATE'
    WHEN 'F ' THEN 'FLOAT'
    WHEN 'I1' THEN 'BYTEINT'
    WHEN 'I2' THEN 'SMALLINT'
    WHEN 'I8' THEN 'BIGINT'
    WHEN 'I ' THEN 'INTEGER'
    WHEN 'AT' THEN 'TIME('            || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'TS' THEN 'TIMESTAMP('       || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'TZ' THEN 'TIME('            || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || ')' || ' WITH TIME ZONE'
    WHEN 'SZ' THEN 'TIMESTAMP('       || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || ')' || ' WITH TIME ZONE'
    WHEN 'YR' THEN 'INTERVAL YEAR('   || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'YM' THEN 'INTERVAL YEAR('   || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'      || ' TO MONTH'
    WHEN 'MO' THEN 'INTERVAL MONTH('  || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'DY' THEN 'INTERVAL DAY('    || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'DH' THEN 'INTERVAL DAY('    || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'      || ' TO HOUR'
    WHEN 'DM' THEN 'INTERVAL DAY('    || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'      || ' TO MINUTE'
    WHEN 'DS' THEN 'INTERVAL DAY('    || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'      || ' TO SECOND('
                                      || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'HR' THEN 'INTERVAL HOUR('   || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'HM' THEN 'INTERVAL HOUR('   || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'      || ' TO MINUTE'
    WHEN 'HS' THEN 'INTERVAL HOUR('   || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'      || ' TO SECOND('
                                      || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'MI' THEN 'INTERVAL MINUTE(' || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'MS' THEN 'INTERVAL MINUTE(' || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ')'      || ' TO SECOND('
                                      || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'SC' THEN 'INTERVAL SECOND(' || TRIM(DecimalTotalDigits (FORMAT '-(9)9')) || ',' 
                                      || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || ')'
    WHEN 'BO' THEN 'BLOB('            || TRIM(ColumnLength (FORMAT 'Z(9)9')) || ')'
    WHEN 'CO' THEN 'CLOB('            || TRIM(ColumnLength (FORMAT 'Z(9)9')) || ')'

    WHEN 'PD' THEN 'PERIOD(DATE)'     
    WHEN 'PM' THEN 'PERIOD(TIMESTAMP('|| TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || ')' || ' WITH TIME ZONE)'
    WHEN 'PS' THEN 'PERIOD(TIMESTAMP('|| TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || '))'
    WHEN 'PT' THEN 'PERIOD(TIME('     || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || '))'
    WHEN 'PZ' THEN 'PERIOD(TIME('     || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) || ')' || ' WITH TIME ZONE)'
    WHEN 'UT' THEN COALESCE(ColumnUDTName,  '<Unknown> ' || ColumnType)

    WHEN '++' THEN 'TD_ANYTYPE'
    WHEN 'N'  THEN 'NUMBER('          || CASE WHEN DecimalTotalDigits = -128 THEN '*' ELSE TRIM(DecimalTotalDigits (FORMAT '-(9)9')) END
                                      || CASE WHEN DecimalFractionalDigits IN (0, -128) THEN '' ELSE ',' || TRIM(DecimalFractionalDigits (FORMAT '-(9)9')) END
                                      || ')'
    WHEN 'A1' THEN COALESCE('SYSUDTLIB.' || ColumnUDTName,  '<Unknown> ' || ColumnType)
    WHEN 'AN' THEN COALESCE('SYSUDTLIB.' || ColumnUDTName,  '<Unknown> ' || ColumnType)

    WHEN 'JN' THEN 'JSON('            || TRIM(ColumnLength (FORMAT 'Z(9)9')) || ')'
    WHEN 'VA' THEN 'TD_VALIST'
    WHEN 'XM' THEN 'XML'

    ELSE '<Unknown> ' || ColumnType
  END 
  || CASE
        WHEN ColumnType IN ('CV', 'CF', 'CO') 
        THEN CASE CharType 
                WHEN 1 THEN ' CHARACTER SET LATIN'
                WHEN 2 THEN ' CHARACTER SET UNICODE'
                WHEN 3 THEN ' CHARACTER SET KANJISJIS'
                WHEN 4 THEN ' CHARACTER SET GRAPHIC'
                WHEN 5 THEN ' CHARACTER SET KANJI1'
                ELSE ''
             END
         ELSE ''
      END
;


SELECT
   DatabaseName,
   TableName,
   ColumnName,

   DataTypeString
    (ColumnType,
     ColumnLength,
     DecimalTotalDigits,
     DecimalFractionalDigits,
     CharType,
     ColumnUDTName),

   ColumnType,
   ColumnLength,
   DecimalTotalDigits,
   DecimalFractionalDigits,
   CharType
FROM dbc.ColumnsV
WHERE ColumnType IS NOT NULL
ORDER BY 4
ORDER BY 1,2,3
;

答案 1 :(得分:0)

SELECT 
  trim(ColumnName) ||
  case columnType
    when 'CV' then ' varchar(' || trim(ColumnLength) || ') '
    when 'DA' then ' date '
    when 'F' then ' float '
    when 'N' then ' number '
    when 'D' then ' decimal(' || trim(DecimalTotalDigits) || ',' || trim(DecimalFractionalDigits) || ') '
    when 'TS' then ' timestamp( ' || trim(ColumnLength) || ') '
    when 'AT' then ' time '
    when 'CF' then ' char(' || trim(ColumnLength) || ') '
  end ColumnDef
FROM DBC.columns s1
WHERE databasename='$database' and tablename='$table';

答案 2 :(得分:0)

我不知道DBC中包含此信息的任何表,但您可以在Teradata文档中找到此信息(并可能将其加载到您自己的表中)。

数据字典文档指定DBC.Columns中ColumnType的所有可能值。我在TD 15.10的文档(第3章,第94页)中列出了该列表的开头(如果有帮助的话)。

Value   Description
----------------------------------------------------------
++      TD_ANYTYPE
A1      One dimensional ARRAY data type
AT      ANSI Time
BF      BYTE Fixed
BO      Byte Large Object

我没有检查向后兼容性,但它几乎肯定是向后兼容的(没有理由不应该这样)。同一文档包含许多有关大量DBC对象中可能值的有用信息。