Commit a17c567f authored by wax@kishkin.ru's avatar wax@kishkin.ru

replace default separator in group_concat, correct a bug

parent b24eeb7f
...@@ -14,18 +14,18 @@ insert into t1 values (3,9,"D","c"); ...@@ -14,18 +14,18 @@ insert into t1 values (3,9,"D","c");
select grp,group_concat(c) from t1 group by grp; select grp,group_concat(c) from t1 group by grp;
grp group_concat(c) grp group_concat(c)
1 a 1 a
2 b c 2 b,c
3 E C D d d D 3 E,C,D,d,d,D
select grp,group_concat(a,c) from t1 group by grp; select grp,group_concat(a,c) from t1 group by grp;
grp group_concat(a,c) grp group_concat(a,c)
1 1a 1 1a
2 2b 3c 2 2b,3c
3 4E 5C 6D 7d 8d 9D 3 4E,5C,6D,7d,8d,9D
select grp,group_concat("(",a,":",c,")") from t1 group by grp; select grp,group_concat("(",a,":",c,")") from t1 group by grp;
grp group_concat("(",a,":",c,")") grp group_concat("(",a,":",c,")")
1 (1:a) 1 (1:a)
2 (2:b) (3:c) 2 (2:b),(3:c)
3 (4:E) (5:C) (6:D) (7:d) (8:d) (9:D) 3 (4:E),(5:C),(6:D),(7:d),(8:d),(9:D)
select grp,group_concat(c separator ",") from t1 group by grp; select grp,group_concat(c separator ",") from t1 group by grp;
grp group_concat(c separator ",") grp group_concat(c separator ",")
1 a 1 a
...@@ -39,48 +39,48 @@ grp group_concat(c separator "---->") ...@@ -39,48 +39,48 @@ grp group_concat(c separator "---->")
select grp,group_concat(c order by c) from t1 group by grp; select grp,group_concat(c order by c) from t1 group by grp;
grp group_concat(c order by c) grp group_concat(c order by c)
1 a 1 a
2 b c 2 b,c
3 C D d d D E 3 C,D,d,d,D,E
select grp,group_concat(c order by c desc) from t1 group by grp; select grp,group_concat(c order by c desc) from t1 group by grp;
grp group_concat(c order by c desc) grp group_concat(c order by c desc)
1 a 1 a
2 c b 2 c,b
3 E D d d D C 3 E,D,d,d,D,C
select grp,group_concat(d order by a) from t1 group by grp; select grp,group_concat(d order by a) from t1 group by grp;
grp group_concat(d order by a) grp group_concat(d order by a)
1 a 1 a
2 a b 2 a,b
3 a b b d d c 3 a,b,b,d,d,c
select grp,group_concat(d order by a desc) from t1 group by grp; select grp,group_concat(d order by a desc) from t1 group by grp;
grp group_concat(d order by a desc) grp group_concat(d order by a desc)
1 a 1 a
2 b a 2 b,a
3 c d d b b a 3 c,d,d,b,b,a
select grp,group_concat(a order by a,d+c) from t1 group by grp; select grp,group_concat(a order by a,d+c) from t1 group by grp;
grp group_concat(a order by a,d+c) grp group_concat(a order by a,d+c)
1 1 1 1
2 2 3 2 2,3
3 4 5 6 7 8 9 3 4,5,6,7,8,9
select grp,group_concat(c order by 1) from t1 group by grp; select grp,group_concat(c order by 1) from t1 group by grp;
grp group_concat(c order by 1) grp group_concat(c order by 1)
1 a 1 a
2 b c 2 b,c
3 C D d d D E 3 C,D,d,d,D,E
select grp,group_concat(c order by "c") from t1 group by grp; select grp,group_concat(c order by "c") from t1 group by grp;
grp group_concat(c order by "c") grp group_concat(c order by "c")
1 a 1 a
2 b c 2 b,c
3 C D d d D E 3 C,D,d,d,D,E
select grp,group_concat(distinct c order by c) from t1 group by grp; select grp,group_concat(distinct c order by c) from t1 group by grp;
grp group_concat(distinct c order by c) grp group_concat(distinct c order by c)
1 a 1 a
2 b c 2 b,c
3 C D E 3 C,D,E
select grp,group_concat(distinct c order by c desc) from t1 group by grp; select grp,group_concat(distinct c order by c desc) from t1 group by grp;
grp group_concat(distinct c order by c desc) grp group_concat(distinct c order by c desc)
1 a 1 a
2 c b 2 c,b
3 E D C 3 E,D,C
select grp,group_concat(c order by c separator ",") from t1 group by grp; select grp,group_concat(c order by c separator ",") from t1 group by grp;
grp group_concat(c order by c separator ",") grp group_concat(c order by c separator ",")
1 a 1 a
...@@ -104,8 +104,8 @@ grp group_concat(distinct c order by c desc separator ",") ...@@ -104,8 +104,8 @@ grp group_concat(distinct c order by c desc separator ",")
select grp,group_concat(c order by grp desc) from t1 group by grp order by grp; select grp,group_concat(c order by grp desc) from t1 group by grp order by grp;
grp group_concat(c order by grp desc) grp group_concat(c order by grp desc)
1 a 1 a
2 c b 2 c,b
3 D d d D C E 3 D,d,d,D,C,E
select grp, group_concat(a separator "")+0 from t1 group by grp; select grp, group_concat(a separator "")+0 from t1 group by grp;
grp group_concat(a separator "")+0 grp group_concat(a separator "")+0
1 1 1 1
...@@ -138,7 +138,7 @@ select grp,group_concat(c order by c) from t1 group by grp; ...@@ -138,7 +138,7 @@ select grp,group_concat(c order by c) from t1 group by grp;
grp group_concat(c order by c) grp group_concat(c order by c)
1 NULL 1 NULL
2 b 2 b
3 D D E 3 D,D,E
4 4
5 NULL 5 NULL
set group_concat_max_len = 5; set group_concat_max_len = 5;
...@@ -146,7 +146,7 @@ select grp,group_concat(c) from t1 group by grp; ...@@ -146,7 +146,7 @@ select grp,group_concat(c) from t1 group by grp;
grp group_concat(c) grp group_concat(c)
1 NULL 1 NULL
2 b 2 b
3 E D D 3 E,D,D
4 4
5 NULL 5 NULL
Warnings: Warnings:
......
...@@ -697,6 +697,7 @@ class Item_func_group_concat : public Item_sum ...@@ -697,6 +697,7 @@ class Item_func_group_concat : public Item_sum
enum Sumfunctype sum_func () const {return GROUP_CONCAT_FUNC;} enum Sumfunctype sum_func () const {return GROUP_CONCAT_FUNC;}
const char *func_name() const { return "group_concat"; } const char *func_name() const { return "group_concat"; }
enum Type type() const { return SUM_FUNC_ITEM; } enum Type type() const { return SUM_FUNC_ITEM; }
void fix_length_and_dec() { max_length=group_concat_max_len; }
virtual Item_result result_type () const { return STRING_RESULT; } virtual Item_result result_type () const { return STRING_RESULT; }
void reset(); void reset();
bool add(); bool add();
...@@ -715,4 +716,5 @@ class Item_func_group_concat : public Item_sum ...@@ -715,4 +716,5 @@ class Item_func_group_concat : public Item_sum
return res ? strtoll(res->c_ptr(),(char**) 0,10) : (longlong) 0; return res ? strtoll(res->c_ptr(),(char**) 0,10) : (longlong) 0;
} }
String* val_str(String* str); String* val_str(String* str);
Item *copy_or_same(THD* thd) { return new Item_func_group_concat(thd, *this); }
}; };
...@@ -2588,7 +2588,7 @@ opt_distinct: ...@@ -2588,7 +2588,7 @@ opt_distinct:
|DISTINCT { $$ = 1; }; |DISTINCT { $$ = 1; };
opt_gconcat_separator: opt_gconcat_separator:
/* empty */ { $$ = new String(" ",1,default_charset_info); } /* empty */ { $$ = new String(",",1,default_charset_info); }
|SEPARATOR_SYM text_string { $$ = $2; }; |SEPARATOR_SYM text_string { $$ = $2; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment