File: json_group_concat.inc

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (51 lines) | stat: -rw-r--r-- 1,971 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--echo # ----------------------------------------------------------------------
--echo # Test of aggregate function GROUP_CONCAT
--echo # ----------------------------------------------------------------------
create table t2(j json);
insert into t2 values (json_array(ST_GeomFromText('LineString(0 0, 1 1, 2 2)')));
select group_concat(j order by j) from t2;
drop table t2;

# MySQL and ECMA strings have different sets of printable control
# character conventions. So make sure we get the desired test
# characters in by inserting them one by one and checking that we insert
# a single character,  which we can test JSON_QUOTE on:

create table t (c varchar(20)) charset utf8mb4;
insert into t values ('\\');
select char_length(c) from t;
insert into t values (X'0C');                   # formfeed \f
select sum(char_length(c)) from t;
insert into t values ('"');
select sum(char_length(c)) from t;
insert into t values ('\a');
select sum(char_length(c)) from t;
insert into t values ('\b');
select sum(char_length(c)) from t;
insert into t values ('\t');
select sum(char_length(c)) from t;
insert into t values ('\n');
select sum(char_length(c)) from t;
insert into t values ('\r');
select sum(char_length(c)) from t;
insert into t values (X'10');                   # needs \u escape
select sum(char_length(c)) from t;

--echo # '\b' and X'10' order equal in the default collation, so order on
--echo # hex(c) as a tie-breaker to get stable results.
select group_concat(c order by c, hex(c)) from t;
select char_length(group_concat(c)) from t;
select json_quote(group_concat(c order by c, hex(c))) from t;
select char_length(json_quote(group_concat(c))) from t;

select convert(group_concat(c) using utf8mb4) =
       json_unquote(group_concat(c)) as should_be_equal from t;

delete from t;
alter table t add column (j json);
insert into t values (NULL, NULL);

select json_quote(c), json_quote(j) from t;
select json_unquote(c), json_unquote(j) from t;

drop table t;