简体   繁体   中英

Maximum length allowed in GROUP_CONCAT ? How to pass it?

In mySQL I use 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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