Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum length allowed in GROUP_CONCAT ? How to pass it?

Tags:

php

mysql

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?

like image 899
EnexoOnoma Avatar asked Aug 30 '14 18:08

EnexoOnoma


1 Answers

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

like image 72
John Ruddell Avatar answered Nov 05 '22 10:11

John Ruddell