[英]MySQL Set collate by a variable
to avoid a "mix of illegal colletions" while updating databases on different systems I want to do something like that: 为了避免在不同系统上更新数据库时出现“非法勾结”现象,我想这样做:
SELECT @collcation := TABLE_COLLATION FROM information_schema.tables WHERE table_schema = "information_schema" AND TABLE_NAME = "COLUMNS";
SELECT * FROM ... WHERE COLUMN_NAME="extended" COLLATE @collcation;
Is it possible to set the COLLATE from a variable? 是否可以通过变量设置COLLATE?
Here my example: 这是我的例子:
select @collcation := TABLE_COLLATION
from information_schema.tables
where table_schema='testdrive_unit_test' and TABLE_NAME = "car"
;
+--------------------------------+
| @collcation := TABLE_COLLATION |
+--------------------------------+
| latin1_swedish_ci |
+--------------------------------+
select * from car order by model collate @collcation
;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@collcation' at line 1
select * from car order by model collate latin1_swedish_ci limit 3
;
+----+----------+-------+----------+
| id | brand_id | model | maxSpeed |
+----+----------+-------+----------+
| 14 | 5 | 301 | 160 |
| 15 | 5 | 401 | 190 |
| 16 | 5 | 407 | 210 |
+----+----------+-------+----------+
3 rows in set (0.00 sec)
In this opinion i think that it isn't possible set the collate from a variable. 根据这种观点,我认为不可能通过变量设置整理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.