JSON Data Type | INSERT Examples | VantageCloud Lake - Examples: Inserting Values into a JSON Column - 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

Example: INSERT Statement

The example creates a table with a JSON column, allocates and initializes a JSON instance using the JSON constructor, then inserts the JSON and integer values into the table.

CREATE TABLE my_table (eno INTEGER, edata JSON(100));
INSERT INTO my_table VALUES(1, 
	NEW JSON('{"name" : "Cameron", "age" : 24}')); 

The example inserts a JSON string into a table that contains a JSON column.

INSERT INTO my_table VALUES(2, 
	'{"name" : "Cameron", "age" : 24}');
If the string is not formatted correctly, an error is reported.
INSERT INTO my_table VALUES(3,
	'{"name" : "Cameron"');
*** Failure 7548: Syntax error in JSON string: expected a '}'.

Example: INSERT SELECT Statement

The example creates two tables, then inserts JSON data into the second table from the first table.

CREATE TABLE my_table (eno INTEGER, edata JSON(100));
CREATE TABLE my_table2 (eno INTEGER, edata JSON(20));
INSERT INTO my_table VALUES(1, 
	NEW JSON('{"name" : "Cam"}'));
INSERT INTO my_Table2
	SELECT * FROM my_table;
If the JSON data is too large to fit in the column an error is reported.
INSERT INTO my_table VALUES(1, 
	NEW JSON('{"name" : "Cameron", "age" : 24}'));
INSERT INTO my_Table2
	SELECT * FROM my_table;
*** Failure 7548: Data too large for this JSON instance.