I create one view in MySQL and after that try use in Metabase with CUSTOM QUESTION and it is introducing the message below, but if I use the NATIVE QUERY is not happening the issue:
Illegal mix of collations (utf8mb4_unicode_ci,EXPLICIT) and (utf8_general_ci,COERCIBLE) for operation '<'
This one happening when use the instructions SQL to create one column:
select
CAST(IF(((TIME_FORMAT(`m`.`mov_ini_atividade`, '%H:%i') < '12:00')
AND (TIME_FORMAT(`m`.`mov_ter_atividade`, '%H:%i') > '12:00')),
((TIME_TO_SEC(TIME_FORMAT(TIMEDIFF(`m`.`mov_ter_atividade`,
`m`.`mov_ini_atividade`),
'%H:%i')) / (60 * 60)) - 1),
(TIME_TO_SEC(TIME_FORMAT(TIMEDIFF(`m`.`mov_ter_atividade`,
`m`.`mov_ini_atividade`),
'%H:%i')) / (60 * 60)))
AS DECIMAL (10 , 2 )) AS `hs_produtiva`,
placa
from
`movem` `m`
Anybody already solve this one issue? I already adjust all the variables in Server MySQL but is not working.
Hi @edimar
Well, probably one of the most annoying things about MySQL - collation.
You have a mix of utf8mb4_unicode_ci and utf8_general_ci
You should use utf8mb4_unicode_ci everywhere - never use utf8_general_ci (or any other utf8_...)
@edimar I couldn't read it, so thought I might as well adjust it
Remember that collation is not just variables, it's also the database and table and columns.
I really hate collation and it's probably one of the things that most people get wrong in their setup.
A good rule on a new setup is to only use utf8mb4, but it's a lot more difficult on an existing database, which might have a mix of collations and it's not always easy to convert them.
@flamber, In this case, what the your orientation? Create a new database? If create a New Database with collate correct, do you thing that it is possible to restore a backup from legacy database?
@edimar Try exporting your database (including Views) - that should show any charset or collation that might be bad in the SQL dump.
As for complete restore of MySQL - I would recommend that you have a look on stackoverflow.com for information about how to best handle that. It's way outside Metabase.
-- Set the database name to the Metabase metadata database - change it to match your db:
USE metabase;
-- Show system variables
SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';
-- Show metadata database/tables/columns
SELECT TABLE_SCHEMA,
TABLE_NAME,
CCSA.CHARACTER_SET_NAME AS DEFAULT_CHAR_SET,
COLUMN_NAME,
COLUMN_TYPE,
C.CHARACTER_SET_NAME,
C.COLLATION_NAME
FROM information_schema.TABLES AS T
JOIN information_schema.COLUMNS AS C USING (TABLE_SCHEMA, TABLE_NAME)
JOIN information_schema.COLLATION_CHARACTER_SET_APPLICABILITY AS CCSA
ON (T.TABLE_COLLATION = CCSA.COLLATION_NAME)
WHERE TABLE_SCHEMA=SCHEMA()
AND C.DATA_TYPE IN ('enum', 'varchar', 'char', 'text', 'mediumtext', 'longtext')
ORDER BY TABLE_SCHEMA,
TABLE_NAME,
COLUMN_NAME;
Ok, but the query it is working well in the database not Metabase and the same query run very good using the Native Query in Metabase enviroment, but if I choose the Custom Question the view not appear.
@edimar
So is the rest of the database (or View) using utf8 or utf8mb4?
Post "Diagnostic Info" from Admin > Troubleshooting, and which version of MySQL you're using.
Check your MySQL log for more details.