Unpack Function Example | Teradata Vantage - Unpack Example: IgnoreInvalid ('true') with Trailing Special Characters - Teradata® Database

Database Analytic Functions

Product
Teradata® Database
Release Number
17.10
Published
July 2021
Language
English (United States)
Last Update
2021-07-28
dita:mapPath
Teradata_Vantage™___Advanced_SQL_Engine_Analytic_Functions.withLogo_upload_July2021/wnd1589838592459.ditamap
dita:ditavalPath
Teradata_Vantage™___Advanced_SQL_Engine_Analytic_Functions.withLogo_upload_July2021/ayr1485454803741.ditaval
dita:id
B035-1206
lifecycle
previous
Product Category
Teradata Vantage™

In this example, the items in the first virtual input column have trailing special characters. No delimiter separates the virtual columns. ColumnLength is 2. The call to Unpack includes IgnoreInvalid ('true'), but the output is unexpected.

Input

t2
c1
1,1919-04-05
1.1919-04-05
5,.1919-04-05
2,2019/04/05
4.,.1919-04-05
32019/04/05

SQL Call

SEL * FROM Unpack (
  ON t2
  USING
  TargetColumn ('c1')
  OutputColumns ('a','b')
  OutputDataTypes ('int','date')
  ColumnLength ('2','*')
  IgnoreInvalid ('True')
) AS dt;

Output

a b
1 19/04/05
1 19/04/05
2 19/04/05

The reason for the unexpected output is the behavior of an internal library that Unpack uses, which is as follows:

Input Row Behavior
1,1919-04-05 Library prunes trailing comma, converts "1" to integer and "1919-04-05" to date. (Output row 1.)
1.1919-04-05 Library prunes trailing period, converts "1" to integer and "1919-04-05" to date. (Output row 2.)
5,.1919-04-05 Library prunes trailing comma, converts 5 to integer, but cannot convert ".1919-04-05" to date. (No output row.)

With ColumnLength ('3','*'), library prunes trailing comma and period, converts "5" to integer and "1919-04-05" to date, and outputs a row for this input row.

2,2019/04/05 Library prunes trailing comma, converts "2" to integer and "1919/04/05" to date. (Output row 3.)
4.,.1919-04-05 Library converts "4." to integer, but cannot convert ",.1919-04-05" to date. (No output row.)
32019/04/05 Library converts "32" to integer, but cannot convert "019/04/05" to date. (No output row.)