Example: Query a 2-D ARRAY Data Type and Table using OEXTEND - 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 2-D ARRAY data type and table.

CREATE TYPE shot_ary AS VARRAY(1:50)(1:50) OF INTEGER;
CREATE TABLE seismic_table (
   id INTEGER,
   shots shot_ary);

The table is populated with the following values:

/* The first 2 elements are populated; the rest are uninitialized. */
INSERT INTO seismic_table VALUES (1, shot_ary(11, 12));
/* Empty ARRAY instance */
INSERT INTO seismic_table VALUES (2, shot_ary());
/* Update empty ARRAY instance such that element [1][3] is set to a value; Then elements [1][1] and [1][2] are set to NULL, the rest are uninitialized */
UPDATE seismic_table
SET shots[1][3] = 1133
WHERE id = 2;

The following query extends the shots array with a single NULL element.

SELECT id, shots.OEXTEND()
FROM seismic_table;

The following is the result of the query.

ID          shots.OEXTEND()
--          ---------------
 1           (11,12,NULL) 
 2           (NULL,NULL,1133,NULL)

The following query extends the shots array with three NULL elements.

SELECT id, shots.OEXTEND(3)
FROM seismic_table;

The following is the result of the query.

ID          shots.OEXTEND(3)
--          ----------------
 1           (11,12,NULL,NULL,NULL) 
 2           (NULL,NULL,1133,NULL,NULL,NULL) 

The following query extends the shots array with two copies of element [1][1].

SELECT id, shots.OEXTEND(2, NEW arrayVec(1,1))
FROM seismic_table
WHERE id = 1;

The following is the result of the query.

ID          shots.OEXTEND(2, NEW arrayVec(1,1))
--          -----------------------------------
 1           (11,12,11,11)