6

When I run the following query:

CREATE ALGORITHM = UNDEFINED VIEW d_view_galerias AS (
SELECT id, titulo, 'foto' AS tipo, '' AS embed
FROM d_galeria_fotos
)
UNION (

SELECT id, titulo, 'video' AS tipo, embed
FROM d_galeria_videos
)

I get the error:

Illegal mix of collations (utf8_unicode_ci,COERCIBLE) and (utf8_general_ci,COERCIBLE) for operation '='

"tipo" is getting as utf8_unicode, but the other fields are as utf8_general ... how to make a cast, convert?

4

3 回答 3

7

错误消息在指定时相当令人困惑operation =——这在您发布的查询中并不明显,而是由UNION仅选择不同值的查询引起的。因此,隐式使用相等比较。

无论如何,您始终可以使用该子句强制对列进行排序。COLLATE这是一个示例,假设您要更改列的排序规则tipo

SELECT id, titulo, 'foto' COLLATE utf8_general_ci AS tipo

... 
UNION SELECT id, titulo, 'video' COLLATE utf8_general_ci AS tipo, ...
于 2013-08-20T17:22:14.940 回答
1

我有一个类似的问题。我所做的是隔离导致错误的 where 子句中的比较。我对要比较的值运行了CONVERT函数,以将其与表的排序规则进行比较。

`field` = CONVERT(value USING charset_of_table)

有关使用 CONVERT 的更多详细信息和示例,请参阅此帖子

于 2016-02-01T09:52:59.640 回答
0

在我的 sql 工作台中的 SQL Schema 上,单击设计图标。在那里更改字符集。在我的情况下,错误消失了。

于 2020-06-04T01:33:52.767 回答