DROP DATABASE IF EXISTS json_depth_db; CREATE DATABASE json_depth_db; USE json_depth_db; # ---------------------------------------------------------------------- # Test of JSON_DEPTH function. # ---------------------------------------------------------------------- CREATE TABLE t1(l LONGTEXT) ENGINE = columnstore; # Return NULL INSERT INTO t1 VALUES(NULL); SELECT JSON_DEPTH(l) FROM t1; JSON_DEPTH(l) NULL # Return 1 TRUNCATE t1; INSERT INTO t1 VALUES('{}'); INSERT INTO t1 VALUES('[]'); INSERT INTO t1 VALUES('"abc"'); SELECT JSON_DEPTH(l) FROM t1; JSON_DEPTH(l) 1 1 1 # Error ER_INVALID_TYPE_FOR_JSON CREATE TABLE t2(i int) ENGINE=columnstore; INSERT INTO t2 VALUES(1); SELECT JSON_DEPTH(i) FROM t2; JSON_DEPTH(i) 1 DROP TABLE t2; # Error ER_INVALID_JSON_TEXT_IN_PARAM TRUNCATE t1; INSERT INTO t1 VALUES('abc'); INSERT INTO t1 VALUES('[ "a", true, "b" , { "e" : false }, "c" , null'); SELECT JSON_DEPTH(l) FROM t1; JSON_DEPTH(l) NULL NULL # Return 2 TRUNCATE t1; INSERT INTO t1 VALUES('{ "a" : true, "b" : false, "c" : null }'); INSERT INTO t1 VALUES('[ "a", true, "b" , false, "c" , null ]'); INSERT INTO t1 VALUES('{ "a" : true, "b" : {}, "c" : null }'); INSERT INTO t1 VALUES('[ "a", true, "b" , {}, "c" , null ]'); SELECT JSON_DEPTH(l) FROM t1; JSON_DEPTH(l) 2 2 2 2 # Return 3 TRUNCATE t1; INSERT INTO t1 VALUES('{ "a" : true, "b" : { "e" : false }, "c" : null }'); SELECT JSON_DEPTH(l) FROM t1; JSON_DEPTH(l) 3 DROP TABLE t1; DROP DATABASE json_depth_db;