JSON Data Type | INSERT Examples | Teradata Vantage - Examples: Inserting Values into a JSON Column - 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ā„¢

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 will be 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.