COUNT Result Type and Attributes - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

The following table lists the data type and format for the result of COUNT.

Mode Data Type and Format
Teradata INTEGER and the format is the default format for INTEGER.
COUNT The default is compatibility mode, which disables all extensions that impact external applications.
BIGINT and NUMBER modes impact COUNT performance:
  • Type promotion may entail computing expressions using a different type if the mode is changed. This occurs when the result of the COUNT (*) based expression is materialized as a BIGINT/NUMBER type, and later used as a subexpression for computing another expression. The performance overhead is the same as that incurred when casting COUNT (*) as BIGINT/NUMBER.
  • Because the data type of COUNT (*) changes if the mode is changed, queries that made assumptions on format, title, and data type must be aware of the change.

If the result of COUNT overflows and reports an error, you can cast the result to another data type, a the following example shows.

SELECT CAST(COUNT(*) AS BIGINT)
FROM BIGTABLE;

A similar example is provided for COUNT and rank window functions:

SELECT CAST(COUNT(*) over([PARTITION/ORDER BY]) AS BIGINT)
FROM BIGTABLE; 
SELECT CAST(rank over([PARTITION/ORDER BY]) AS BIGINT)
FROM BIGTABLE;
The CAST is required only for default or compatibility mode. If value of 1 or 2 is specified for NUMBER or BIGINT mode of computing COUNT, then the CAST is optional.

The following table lists the default title for the result of COUNT.

Operation Title
COUNT(x) Count(x)
COUNT(*) Count(*)

COUNT Specification in Aggregate Join Index

You can specify COUNT, COUNT cast to FLOAT OR DECIMAL(38,0), BIGINT, or NUMBER for a COUNT aggregate function in a join index. The following shows a SHOW JOIN INDEX that accommodates data type casts to BIGINT.

The following statement creates the join index on the Block File System.

CREATE JOIN INDEX TEST.j1 ,NO FALLBACK ,CHECKSUM = DEFAULT AS
SELECT COUNT (*)(BIGINT, NAMED a ),TEST.t1.a1
FROM TEST.t1
GROUP BY TEST.t1.a1
PRIMARY INDEX ( a1 );