Question

Is there any way to compare the generated range column in the mysql query ?

SELECT ue.bundle,ue.timestamp,b.id,bv.id as bundleVersionId,bv.start_date,bv.end_date, bv.type,ue.type from (
 SELECT bundle,timestamp,tenant, case when Document_Id ='' then 'potrait'
 WHEN Document_Id<>'' then 'persisted' end   as type from uds_expanded ) ue
 JOIN bundle b on b.name=ue.bundle  join bundle_version bv on b.id=bv.bundle_id 
 WHERE ue.tenant='02306' and ue.timestamp >= bv.start_date and ue.timestamp <=bv.end_date and **ue.type=bv.type ;**

I am getting the following error when I try to compare the types

 Error Code: 1267. Illegal mix of collations (utf8_general_ci,COERCIBLE) and (latin1_swedish_ci,IMPLICIT) for operation '=' 0.000 sec
Was it helpful?

Solution

Stick to one encoding/collation for your entire system. Right now you seem to be using UTF8 one place and latin1 in another place. Convert the latter to use UTF8 as well and you'll be good.

You can change the collation to UTF8 using

alter table <some_table> convert to character set utf8 collate utf8_general_ci;

OTHER TIPS

I think sometimes the issue is we use different orm utilities to generate table and then we want to test queries either by mysql command line or MySql workbench, then this problem comes due to differences of table collation and the command line or app we use. simple way is to define your variables (ones used to test the query against table columns)

ex:

MySQL>
MySQL> set @testCode = 'test2' collate utf8_unicode_ci;
Query OK, 0 rows affected (0.00 sec)

MySQL> select * from test where code = @testCode;

full details

Be aware that the single columns can have their collation.

For example, Doctrine generates columns of VARCHAR type as CHARACTER SET utf8 COLLATE utf8_unicode_ci, and changing the table collation doesen't affect the single columns.

You can change the column's collation with this command:

ALTER TABLE `table` 
CHANGE COLUMN `test` `test` VARCHAR(15) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci'

or in MySql Workbench interface-> right click on the table-> Alter Table and then in the interface click on a column and modify it.

Use ascii_bin where ever possible, it will match up with almost any collation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top