开发者

Allow quoted values in mysql integer columns?

开发者 https://www.devze.com 2022-12-09 04:24 出处:网络
Consider the table schema for table1: id: int country_id: int description: varchar(50) and the query: INSERT INTO table1(id, country_id, description) VALUES (1, \'20\', \'Test Desc\');

Consider the table schema for table1:

id: int
country_id: int
description: varchar(50)

and the query:

INSERT INTO table1(id, country_id, description) VALUES (1, '20', 'Test Desc'); 

This would work under MySQL 4x but will fail under MySQL 5x (ERROR 1067 (42000): Invalid default value for .. ").

I know the reason for this to happen - country_id is int and therefore should not be quoted. Is there a mysql switch under 5x somewhere to make it behave like 4x so the query won't fail?

I've inherited an applicat开发者_如何学运维ion that uses queries like this and I'm looking for a quick fix until I can find the time to fix all the queries.

Thank you


There is no problem with '20'. MySql (5.x) also casts '20' to 20 and => this is a valid insert

0

精彩评论

暂无评论...
验证码 换一张
取 消