INSERT JSON Statement | JSON Shredding | VantageCloud Lake - JSON Shredding with INSERT JSON Statement - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

For simple shredding cases, you can use the INSERT statement to shred the JSON data into a table. For example, consider the following JSON data:

{"pkey":123,"val":1234}
You can use the following INSERT statement to shred this data into the MyTable table:
INSERT INTO MyTable JSON '{"pkey":123,"val":1234}';
You can also use the JSON_TABLE table operator to shred this data, but the SQL is more complicated than using the INSERT statement.
INSERT INTO MyTable
SELECT pkey, val FROM JSON_Table (
    ON (SELECT 1, new JSON ('{"pkey":123,"val":1234}'))
    USING rowexpr('$')
    colexpr('[{"jsonpath" : "$.pkey", "type" : "INTEGER"},
              {"jsonpath" : "$.val", "type" : "INTEGER"}]')
) AS JT(dummy, pkey, val);

Another advantage of using the INSERT statement is that this operation is a one-AMP operation when shredding JSON data that is a string literal. This can improve performance.

For parameterized SQL, INSERT JSON supports VARCHAR, CLOB, and external JSON data types. However, the operation is handled as a two-AMP process. For improved performance, directly specify a JSON literal.