Jay Sidri
Jay Sidri

Reputation: 6406

Allow quoted values in mysql integer columns?

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 application 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

Upvotes: 0

Views: 226

Answers (1)

Svetlozar Angelov
Svetlozar Angelov

Reputation: 21660

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

Upvotes: 1

Related Questions