Example: Query a 1-D ARRAY Data Type and Table using OTRIM - Teradata Vantage NewSQL Engine - 16.20

Teradata Vantageā„¢ Data Types and Literals

prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1143-162K

Consider the following one-dimensional ARRAY data type and table.

CREATE TYPE phonenumbers AS VARRAY(20) OF CHAR(10);
CREATE TABLE employee_info (eno INTEGER, phonelist phonenumbers);

The table is populated with the following values:

/* The first 2 elements are populated; the rest are uninitialized. */
INSERT INTO employee_info VALUES (1, 
   phonenumbers('1112223333', '6195551234'));
/* Empty ARRAY instance */
INSERT INTO employee_info VALUES (2, 
   phonenumbers());
/* Update empty ARRAY instance such that element 3 is set to a value;
   Then elements 1 and 2 are set to NULL, the rest are uninitialized */
UPDATE employee_info
SET phonelist[3] = '8584850000'
WHERE id = 2;

The following query removes the last populated element from the phonelist array.

SELECT eno, phonelist.OTRIM()
FROM employee_info;

The following is the result of the query.

ENO         phonelist.OTRIM()
---         -----------------
 1           ('1112223333')
 2           (NULL,NULL)

The following query removes the last two populated elements from the phonelist array.

SELECT eno, phonelist.OTRIM(2)
FROM employee_info;

The following is the result of the query.

ENO         phonelist.OTRIM(2)
---         ------------------
 1           ()       (the only 2 populated elements were removed so we
                       now have an empty array value)
 2           (NULL)