mirror of
				https://github.com/MariaDB/server.git
				synced 2025-11-04 04:46:15 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			77 lines
		
	
	
	
		
			3.3 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
	
		
			3.3 KiB
		
	
	
	
		
			Text
		
	
	
	
	
	
set names utf8;
 | 
						|
create table t1 (json json);
 | 
						|
show create table t1;
 | 
						|
Table	Create Table
 | 
						|
t1	CREATE TABLE `t1` (
 | 
						|
  `json` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`json`))
 | 
						|
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
 | 
						|
insert into t1 values
 | 
						|
('{  }'),
 | 
						|
('[  ]'),
 | 
						|
('{ "foo" : "bar" }'),
 | 
						|
('{ "foo" : "bar", "baz" : "whatever" }'),
 | 
						|
('[ 1.2, 0.0, "text", 0, null, true, false ]'),
 | 
						|
('[ "string", { "key" : "val", "a" : "b", "c" : [ 10, 9, 8, "seven", 11 ] }]'),
 | 
						|
('{ "ăț€": "val1", "âț€":"val2" }');
 | 
						|
select json, json_normalize(json) from t1
 | 
						|
order by json;
 | 
						|
json	json_normalize(json)
 | 
						|
[  ]	[]
 | 
						|
[ "string", { "key" : "val", "a" : "b", "c" : [ 10, 9, 8, "seven", 11 ] }]	["string",{"a":"b","c":[1.0E1,9.0E0,8.0E0,"seven",1.1E1],"key":"val"}]
 | 
						|
[ 1.2, 0.0, "text", 0, null, true, false ]	[1.2E0,0.0E0,"text",0.0E0,null,true,false]
 | 
						|
{  }	{}
 | 
						|
{ "foo" : "bar" }	{"foo":"bar"}
 | 
						|
{ "foo" : "bar", "baz" : "whatever" }	{"baz":"whatever","foo":"bar"}
 | 
						|
{ "ăț€": "val1", "âț€":"val2" }	{"âț€":"val2","ăț€":"val1"}
 | 
						|
create view v1 as (select json, json_normalize(json) norm_json from t1);
 | 
						|
show create view v1;
 | 
						|
View	Create View	character_set_client	collation_connection
 | 
						|
v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (select `t1`.`json` AS `json`,json_normalize(`t1`.`json`) AS `norm_json` from `t1`)	utf8mb3	utf8mb3_general_ci
 | 
						|
select * from v1
 | 
						|
order by json;
 | 
						|
json	norm_json
 | 
						|
[  ]	[]
 | 
						|
[ "string", { "key" : "val", "a" : "b", "c" : [ 10, 9, 8, "seven", 11 ] }]	["string",{"a":"b","c":[1.0E1,9.0E0,8.0E0,"seven",1.1E1],"key":"val"}]
 | 
						|
[ 1.2, 0.0, "text", 0, null, true, false ]	[1.2E0,0.0E0,"text",0.0E0,null,true,false]
 | 
						|
{  }	{}
 | 
						|
{ "foo" : "bar" }	{"foo":"bar"}
 | 
						|
{ "foo" : "bar", "baz" : "whatever" }	{"baz":"whatever","foo":"bar"}
 | 
						|
{ "ăț€": "val1", "âț€":"val2" }	{"âț€":"val2","ăț€":"val1"}
 | 
						|
select json_normalize(NULL);
 | 
						|
json_normalize(NULL)
 | 
						|
NULL
 | 
						|
select json_normalize('{ "invalid": "no_close"');
 | 
						|
json_normalize('{ "invalid": "no_close"')
 | 
						|
NULL
 | 
						|
drop table t1;
 | 
						|
drop view v1;
 | 
						|
create table t1 (text varchar(200) character set 'latin1');
 | 
						|
insert into t1 values (unhex('22E522'));
 | 
						|
create table t2 (text varchar(200) character set 'utf8mb4');
 | 
						|
insert into t2 SELECT * FROM t1;
 | 
						|
select t1.text, hex(t1.text) from t1;
 | 
						|
text	hex(t1.text)
 | 
						|
"å"	22E522
 | 
						|
select t2.text, hex(t2.text) from t2;
 | 
						|
text	hex(t2.text)
 | 
						|
"å"	22C3A522
 | 
						|
select t1.text
 | 
						|
, t2.text
 | 
						|
, replace(json_normalize(t1.text), unhex('C3A5'), unhex('C385'))
 | 
						|
, replace(json_normalize(t2.text), unhex('C3A5'), unhex('C385'))
 | 
						|
, hex(replace(json_normalize(t1.text), unhex('C3A5'), unhex('C385')))
 | 
						|
, hex(replace(json_normalize(t2.text), unhex('C3A5'), unhex('C385')))
 | 
						|
from t1, t2;
 | 
						|
text	text	replace(json_normalize(t1.text), unhex('C3A5'), unhex('C385'))	replace(json_normalize(t2.text), unhex('C3A5'), unhex('C385'))	hex(replace(json_normalize(t1.text), unhex('C3A5'), unhex('C385')))	hex(replace(json_normalize(t2.text), unhex('C3A5'), unhex('C385')))
 | 
						|
"å"	"å"	"Å"	"Å"	22C38522	22C38522
 | 
						|
drop table t1;
 | 
						|
drop table t2;
 | 
						|
create table t1 (text varchar(1));
 | 
						|
insert into t1 values ('0');
 | 
						|
select concat_ws(' ', t1.text, t1.text) from t1;
 | 
						|
concat_ws(' ', t1.text, t1.text)
 | 
						|
0 0
 | 
						|
select concat_ws(' ', json_normalize(t1.text), json_normalize(t1.text)) from t1;
 | 
						|
concat_ws(' ', json_normalize(t1.text), json_normalize(t1.text))
 | 
						|
0.0E0 0.0E0
 | 
						|
drop table t1;
 |