简体   繁体   English

GROUP_CONCAT允许的最大长度?怎么通过呢?

[英]Maximum length allowed in GROUP_CONCAT ? How to pass it?

In mySQL I use GROUP_CONCAT 在mySQL中,我使用GROUP_CONCAT

SELECT
visits,
GROUP_CONCAT(token) as token
FROM general
GROUP BY visits

but the problem is that I have a huge number of rows with same visits and using PHP it does not allow me to print everything. 但问题是我有大量的行具有相同的访问次数并使用PHP它不允许我打印所有内容。

Is there a workaround for this? 这有解决方法吗?

I ran into the same issue when I was trying to group_concat a string that was too big.. so what I did to solve it was this 当我试图将group_concat变成一个太大的字符串时,我遇到了同样的问题。所以我要解决的问题是这个

SET SESSION group_concat_max_len = 10000000000000000;

this is a temporary function meaning that it wont actually change it forever but only in the scope of your query session. 这是一个临时函数,意味着它实际上不会永远地更改它,而只是在查询会话的范围内。

I wouldn't recommend changing it forever but only for the scope of your query... that way you aren't using up a lot of memory space for that one function.. when you probably don't need to use it all the time 我不建议永远更改它,但仅限于查询的范围......这样你就不会为这一个函数消耗大量的内存空间...当你可能不需要使用它时所有的时间

with that aside if you really want to just reset it to a larger length and not change it for your session then just remove session from the query to set it. 除此之外,如果你真的想将它重置为更大的长度而不是为你的会话更改它,那么只需从查询中删除会话来设置它。

so your query should be like this 所以你的查询应该是这样的

SET SESSION group_concat_max_len = 10000000000000000; -- # -- or whatever size you need to make it
SELECT 
    visits,
    GROUP_CONCAT(token) as token
FROM general
GROUP BY visits;

if you are still getting an error as @spencer7593 correctly noted.. you may need to change your max_allowed_packet ... you can do that from this SO POST 如果您仍然收到错误,因为@ spencer7593正确注意到..您可能需要更改您的max_allowed_packet ...您可以通过此SO POST执行此操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM