Result Type and Format - Advanced SQL Engine - Teradata Database

SQL Functions, Expressions, and Predicates

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

The result data type and format for window aggregate functions are as follows.

Function Result Type Format
AVG(x)

where x is a character type

FLOAT Default format for FLOAT
AVG(x)

where x is a numeric, DATE, or INTERVAL type

FLOAT Same format as operand x
  • CORR(x,y)
  • COVAR_POP(x,y)
  • COVAR_SAMP(x,y)
  • REGR_AVGX( y,x)
  • REGR_AVGY( y,x)
  • REGR_INTERCEPT(x,y)
  • REGR_R2(x,y)
  • REGR_SLOPE(x,y)
  • REGR_SXX(x,y)
  • REGR_SXY(x,y)
  • REGR_SYY(x,y)
  • STDDEV_POP(x,)
  • STDDEV_SAMP(x,)
  • VAR_POP(x,)
  • VAR_SAMP(x)

where x is a character type

FLOAT Default format for FLOAT
  • CORR(x,y)
  • COVAR_POP(x,y)
  • COVAR_SAMP(x,y)
  • REGR_AVGX (y,x)
  • REGR_AVGY( y,x)
  • REGR_INTERCEPT(x,y)
  • REGR_R2(x,y)
  • REGR_SLOPE(x,y)
  • REGR_SXX(x,y)
  • REGR_SXY(x,y)
  • REGR_SYY(x,y)
  • STDDEV_POP(x)
  • STDDEV_SAMP(x)
  • VAR_POP(x)
  • VAR_SAMP(x)
where x is one of the following types:
  • Numeric
  • DATE
  • Interval
Same data type as operand x. Default format for the data type of operand x
REGR_AVGX(y,x)

REGR_AVGY(y, x)

where x is a UDT

  Default format for the data type to which the UDT is implicitly cast.
COUNT(x)

COUNT(*)

REGR_COUNT(x ,y)

where the transaction mode is ANSI

If MaxDecimal in DBSControl is…
  • 0 or 15, then the result type is DECIMAL(15,0) and the format is -(15)9.
  • 18, then the result type is DECIMAL(18,0) and the format is -(18)9.
  • 38, then the result type is DECIMAL(38,0) and the format is -(38)9.

ANSI transaction mode uses DECIMAL because tables frequently have a cardinality exceeding the range of INTEGER.

COUNT(x)

COUNT(*)

REGR_COUNT(x,y)

where the transaction mode is Teradata

INTEGER

Teradata transaction mode uses INTEGER to avoid regression problems.

You can cast the final result of a COUNT window aggregate function; however, the cast is not used as part of the window function computation as it is for the COUNT aggregate function and, therefore, cannot be used to avoid numeric overflow errors that might occur during the computation.
Default format for INTEGER
MAX(x), MIN(x) Same data type as operand x. Same format as operand x
SUM(x)

where x is a character type

Same as operand x. Default format for FLOAT
SUM(x)

where x is a DECIMAL(n,m) type

DECIMAL(p,m), where p is determined according to the following rules:
If MaxDecimal in DBSControl is 0 or 15 and
  • n  ≤  15, then p = 15.
  • 15 < n  ≤  18, p = 18.
  • n  > 18, then p = 38.
If MaxDecimal in DBSControl is 18 and
  • n  ≤  18, then p = 18.
  • n  > 18, then p = 38.

If MaxDecimal in DBSControl is 38 and n  = any value, the p = 38.

Default format for DECIMAL
SUM(x)

where x is any numeric type other than DECIMAL

Same as operand x. Default format for the data type of the operand