Examples | ARRAY_SUM Function | Teradata Vantage - Example: Querying a 1-D ARRAY Data Type and Table using ARRAY_SUM - Advanced SQL Engine - Teradata Database

SQL Data Types and Literals

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
zsn1556242031050.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1143
lifecycle
previous
Product Category
Teradata Vantageā„¢

Consider the following 1-D ARRAY data type and table.

CREATE TYPE item_price AS DECIMAL(7,2) ARRAY[20];
CREATE TABLE inventory (itemkind INTEGER,
                        regular_price item_price,
                        sale_price item_price);

When evaluating the following query, each element value of the regular_price array is added together. The resulting value is divided by 2.

SELECT ARRAY_SUM(regular_price) / 2 FROM inventory;

The following is the same query using method-style syntax.

SELECT regular_price.ARRAY_SUM() / 2 FROM inventory;

In the following query, ARRAY_SUM adds each element within the specified scope of the regular_price array. The query returns a value representing the total sum of adding the affected element values of the regular_price array.

SELECT ARRAY_SUM(regular_price, NEW arrayVec(5,10))FROM inventory;

The following shows an alternate way to specify the same query.

SELECT ARRAY_SUM(regular_price, 5, 10) FROM inventory;