Examples: Shredding JSON Data Using INSERT...JSON - Advanced SQL Engine - Teradata Database

JSON Data Type

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
gzn1554761068186.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1150
lifecycle
previous
Product Category
Teradata Vantageā„¢
CREATE TABLE jsonTable2 
(
    a INTEGER, 
    b INTEGER, 
    c INTEGER NOT NULL DEFAULT 5, 
    j JSON CHARACTER SET LATIN
);

In the following INSERT statement, the input JSON data does not include a value for column c. However, because the input JSON data is a string literal, the DEFAULT value defined for column c is inserted.

INSERT INTO jsonTable2 JSON '{"a":1234,"b":2}';
*** Insert completed. One row added.  ***
CREATE TABLE jsonTable5 
(
    a INTEGER, 
    b INTEGER, 
    j JSON AUTO COLUMN NOT NULL
);

In this example, the input JSON data includes extra data that does not match any columns in jsonTable5. The extra data is inserted into the j AUTO COLUMN. The third INSERT statement does not include any extra data and the AUTO COLUMN is defined as NOT NULL; therefore, '{}' is inserted.

INS jsonTable5 JSON '{"a":1,"b":1,"extra":1}';
INS jsonTable5 JSON '{"a":2,"b":2,"extra1":2,"extra2":222}';
INS jsonTable5 JSON '{"a":3,"b":3};
SELECT * FROM jsonTable5 ORDER BY 1;
          a           b j
----------- ----------- ---------------------------------------------------
          1           1 {"extra":"1"}
          2           2 {"extra1":"2","extra2":"222"}
          3           3 {}