Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 620843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:48:31+00:00 2026-05-13T18:48:31+00:00

I have a MySQL database that is exhibiting behavior I would like to understand

  • 0

I have a MySQL database that is exhibiting behavior I would like to understand better. Why can I search for a CHAR value inserted into an INT field? I have a field that is of type INT but it seems to be able to record character values, how is that possible?

I tried to isolate the issue by creating a database with an INT and VARCHAR. I inserted “TEST1” into the INT value but was still able to search for the row using the ID string value. The warning after inserting the string into the ID value is

| Warning | 1366 | Incorrect integer value: 'TEST1' for column 'ID' at row 1 |

but I was still able to search for that value. I would like to understand why this is possible.

mysql> CREATE TABLE test1(ID int, DATA varchar(255));
Query OK, 0 rows affected (0.18 sec)

mysql> INSERT INTO test1(ID,DATA) VALUES('TEST1', 'TEST1');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> SELECT * FROM test1 WHERE ID = 'TEST1';
+------+-------+
| ID   | DATA  |
+------+-------+
|    0 | TEST1 |
+------+-------+
1 row in set, 1 warning (0.00 sec)

The warning after the SELECT is

| Warning | 1366 | Incorrect integer value: 'TEST1' for column 'ID' at row 1 |

but the results is still correct.

I would expect the SELECT above to find 0 results, but that is not the case, why?

ANSWER:

With the help of Asaph’s answer below and Pekka’s comments the answer seems obvious now.

During the INSERT, MySQL failed to insert the character value into an INT field so it replaced it with 0. The same thing happened during the SELECT so in effect I was doing a SELECT on ID = 0 for any character value I was searching.

mysql> SELECT * FROM test1 WHERE ID = 'SOMETHING_OTHER_THAN_TEST1';
+------+-------+
| ID   | DATA  |
+------+-------+
|    0 | TEST1 |
+------+-------+
1 row in set, 1 warning (0.00 sec)

That returns the same result as the my initial select since it really is running as

SELECT * FROM test1 WHERE ID = 0;

in the backend.

In any case the best practice seems to be to use sql_mode = ‘STRICT_ALL_TABLES’ in the MySQL configuration file or the SQL statement itself.

To enable STRICT_ALL_TABLES for all SQL queries on a MySQL server you need to add the following under the [mysqld] header in your my.cnf file which is usually located in /etc/my.cnf

[mysqld]
...
...
...
sql-mode=STRICT_ALL_TABLES
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:48:31+00:00Added an answer on May 13, 2026 at 6:48 pm

    You can prevent nonsense values from being inserted in the first place by setting the STRICT_ALL_TABLES mode which can be set in my.cnf or on the fly:

    mysql> SET sql_mode = 'STRICT_ALL_TABLES';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> CREATE TABLE test1(ID int, DATA varchar(255));
    Query OK, 0 rows affected (0.42 sec)
    
    mysql> INSERT INTO test1(ID,DATA) VALUES('TEST1', 'TEST1');
    ERROR 1264 (22003): Out of range value adjusted for column 'ID' at row 1
    mysql> SELECT * FROM test1 WHERE ID = 'TEST1';
    Empty set (0.00 sec)
    
    mysql> SELECT * FROM test1;
    Empty set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several columns in a MySQL database that I would like to add
I have a mysql database that is tracking hockey stats. What I'd like to
I have a mysql database that looks like this: |id | city | created
I have to look into solutions for providing a MySQL database that can handle
I have a MySQL database that I want to update with a response value
I have a MySQL database that looks like this: users ( id , name
I have a MySQL database that has a few very simple tables. I would
OK I have a mySQL Database that looks something like this ID - an
My question: I have a mysql database that consists of something like a fact
I have a MySQL database that I'd like to test the performance of. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.