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 8295061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:27:11+00:00 2026-06-08T14:27:11+00:00

I came across this strange behavior when I was hunting for a bug in

  • 0

I came across this strange behavior when I was hunting for a bug in a system. Consider following.

We have a mysql table which have varchar(100) column. See the following sql script.

create table user(`id` bigint(20) NOT NULL AUTO_INCREMENT,`user_id` varchar(100) NOT NULL,`username` varchar(255) DEFAULT NULL,PRIMARY KEY (`id`),UNIQUE KEY `user_id` (`user_id`))  ENGINE=InnoDB AUTO_INCREMENT=129 DEFAULT CHARSET=latin1;

insert into user(user_id, username) values('20120723145614834', 'user1');

insert into user(user_id, username) values('20120723151128642', 'user1');

When I execute following query I received 0 results.

select * from user where user_id=20120723145614834;

But When I execute following I get the result(note the single quote).

select * from user where user_id='20120723145614834';

This is expected since user_id field is varchar. Strange thing is that both following queries yield result.

select * from user where user_id=20120723151128642;
select * from user where user_id='20120723151128642';

Can anybody explain me the reason for this strange behavior. My MySql version is 5.1.63-0ubuntu0.11.10.1

  • 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-06-08T14:27:13+00:00Added an answer on June 8, 2026 at 2:27 pm

    Check mysql document 12.2. Type Conversion in Expression Evaluation

    Comparisons that use floating-point numbers (or values that are
    converted to floating-point numbers) are approximate because such
    numbers are inexact. This might lead to results that appear
    inconsistent:

    mysql> SELECT '18015376320243458' = 18015376320243458;
            -> 1
    mysql> SELECT '18015376320243459' = 18015376320243459;
            -> 0
    

    So we better use always right data type for SQL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I came across this line in a MySQL script `other_validator` varchar(5000) NOT NULL DEFAULT
While working on a WebSocket server in Java I came across this strange bug.
I came across on a strange behavior of the following code, while playing around
While exploring for scjp questions, I came across this behaviour which I found strange.
I came across this strange code snippet which compiles fine: class Car { public:
I came across a strange behavior in Python (2.6.1) dictionaries: The code I have
I came across this strange behavior in Google Chrome recently (version 17.0): I defined
I came across this strange bit of CSS tonight... display: inline !ie; Now I've
Came across this code: <?php require_once 'HTTP/Session/Container/DB.php'; $s = new HTTP_Session_Container_DB('mysql://user:password@localhost/db'); ini_get('session.auto_start') or session_start();
I came across this due to a bug in my code and I'm curious

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.