Search code examples
mysqlprepared-statement

"Unknowm column in field list" - error from truncated column name


I built a prepared statement which renames TEST01 columns into columns mapped in a table named MAPPING.

For a specific column named 'localization', I get this error message: MySQL said: #1054 - Unknown column 'loca' in 'field list' . I don't understand why this one in particular since there are other columns with longer names and they did not trigger the same error.

BEGIN
    SELECT CONCAT(
        'CREATE TABLE `table_client_normalized` AS SELECT * FROM (SELECT ',
     GROUP_CONCAT(CONCAT(client_label, ' AS ', master_label)), ', ',  
        QUOTE(MAX(clientid)), ' AS client_id ',
      'FROM TEST01'
    ') A' ) INTO @sql
        FROM `MAPPING` B;

    PREPARE stmt FROM @sql;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;

END

I compared the data structure on each table and aligned them to: varchar(100), utf8_bin.

If I rename the columns (both on TEST01 and MAPPING) into loca or anything shorter than 4 characters, the query will work.

So, it seems to be a size issue but I don't understand the reason behind, why the problem only on that specific column and what to do to solve this issue.

Thank you for your help.


Solution

  • from https://dev.mysql.com/doc/refman/8.0/en/group-by-functions.html#function_group-concat:

    The result is truncated to the maximum length that is given by the group_concat_max_len system variable, which has a default value of 1024.