Search code examples
mysqlutf-8utf8mb4

How to use emojis (or other utf8mb4) characters in a column alias of a MySQL query?


I'm using SuiteCRM 7 with a MySQL 8.0.31 database. I have taken steps to migrate the MySQL database to accept utf8mb4 characters which works well when entering in, say, emojis into table data either with the SuiteCRM web frontend or HeidiSQL.

I am now trying to create a report that uses an emoji in a column alias. SuiteCRM constructs queries that look like:

SELECT count(*) c FROM (SELECT `cases`.id AS 'ID_😀0', `cases`.id AS 'cases_id' FROM `cases`  WHERE cases.deleted = 0 ) AS n;

and the MySQL server responds with:

Query Failed: SELECT cases.id AS 'ID_😀0', cases.id AS 'cases_id' FROM cases WHERE cases.deleted = 0 LIMIT 0,60: MySQL error 3854: Cannot convert string 'ID_\xF0\x9F\x98...' from utf8mb4 to utf8mb3

A similar query (that omits the emoji) works fine:

SELECT count(*) c FROM (SELECT `cases`.id AS 'ID_test0', `cases`.id AS 'cases_id' FROM `cases`  WHERE cases.deleted = 0 ) AS n;
  • Is there a setting I can change on the MySQL server (AWS RDS-based) to make this query work as-is?
  • or is there a way I should reformat the query to make it work?
  • or is this a shortcoming of MySQL and emojis or other utf8mb4-specific characters won't work in column aliases?

Thanks!

I have tried configuring MySQL to generate general logs but I did not see any useful information. I also looked into the error code 3854 and did not find anything useful so far. I double-checked that I could enter in emojis into table data successfully.


Solution

  • Alas, I think it is not possible. Certain system tables (such as the one including column names) is declared CHARACTER SET utf8 (aka `utf8mb3). Emojis need utf8mb4.