MySQL使用group_concat
和union
结果被截断。
表test_b
CREATE TABLE "test_b" (
"id" int(11) NOT NULL AUTO_INCREMENT,
"name" varchar(255) NOT NULL,
"status" tinyint(2) NOT NULL DEFAULT '1',
PRIMARY KEY ("id")
)
测试1:
select GROUP_CONCAT(id) ids from test_b where id <200
UNION
select GROUP_CONCAT(id) ids from test_b where id >900
测试2:
select GROUP_CONCAT(id) ids from test_b where id <200
UNION
select null ids
测试3:
select GROUP_CONCAT(id) ids from test_b where id <10
UNION
select GROUP_CONCAT(id) ids from test_b where id >900
测试了截断行的长度:select LENGTH('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,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,1')
结果为341。
查了mysql文档也没有找到原因,求解。
首先,你要确定是你用的MySQL客户端截断的,还是MySQL返回时就截断的?测试方法很简单:
如果是后者,可以考虑在配置(my.cnf或my.ini)中把
group_concat_max_len
设得大些,或者每次连接时执行SET SESSION group_concat_max_len = 1000000
。