Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Mysql Perpared statement increase the set variable length

    set @sql1 = '';

    SELECT
      GROUP_CONCAT(DISTINCT
        CONCAT(
          'MAX(IF(field_id = ''',
          field_id,
          ''', value, NULL)) AS `',
          field_id,'`'
        )
      ) INTO @sql1
    FROM content_details;
    SET @sql1 = CONCAT('SELECT  ', @sql1, ' FROM content_details GROUP BY content_id');
    select @sql1;
    PREPARE stmt FROM @sql1;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    

In above code @sql1 variable storing some limited characters only. Here I am concating string dynamically. I donot know the exact total length of the string what will come future. my question is how we can set the unlimited char length to the $sql1 variable. Please advice.

like image 631
Sathish Babu Avatar asked Dec 16 '22 10:12

Sathish Babu


1 Answers

It sounds like you are having an issue with the GROUP_CONCAT_MAX_LEN. You can adjust the length of this variable during your session.

The default length of this variable is 1024. You should be able to use:

set session group_concat_max_len = yourNewValue;

If you were to set this globally it would impact all other connections, that is why you might only want to set it for your session.

like image 174
Taryn Avatar answered Dec 17 '22 22:12

Taryn