简体   繁体   English

禁用保留VARCHAR列的尾随空格

[英]Disable the retention of trailing spaces for VARCHAR columns

We are considering migrating from MySQL 4.x to MySQL 5.x. 我们正在考虑从MySQL 4.x迁移到MySQL5.x。

However, beginning with MySQL 5.0.3, trailing spaces are retained in VARCHAR columns, whereas in MySQL 4.x, trailing spaces were not retained for VARCHAR columns. 但是,从MySQL 5.0.3开始,在VARCHAR列中保留尾随空格,而在MySQL 4.x中,未为VARCHAR列保留尾随空格。

It was suggested that there might be a MySQL setting that allows us to tell MySQL 5.x to behave as it did in MySQL 4.x, and not retain trailing spaces. 建议可能存在一个MySQL设置,该设置允许我们告诉MySQL 5.x像在MySQL 4.x中那样运行,并且不保留尾随空格。

I'm unable to find such a setting, but maybe I'm overlooking it. 我找不到这样的设置,但也许我忽略了它。 Is there a way to do this? 有没有办法做到这一点?

AFAIK there is no SQL mode for reverting to the old behaviour. AFAIK没有SQL模式可还原为旧的行为。 If your application relies on this behaviour your best bet might be to use BEFORE INSERT TRIGGERS to trim varchar values. 如果您的应用程序依赖于此行为,那么最好的选择是使用INSERT TRIGGERS之前的方法来修剪varchar值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM