0

All,

I'm wondering if this is a MySQL bug, but since I've seen others playing with larger numbers than this, I'm thinking I'm doing something wrong here.

Here is my table structure for the table I'm querying: mysql> describe ipspace6\G
*************************** 1. row ***************************
Field: id
Type: decimal(39,0) unsigned
Null: NO
Key:
Default: NULL
Extra:
*************************** 2. row ***************************
Field: addr
Type: decimal(39,0) unsigned
Null: NO
Key: PRI
Default: 0
Extra:
*************************** 3. row ***************************
Field: netmask
Type: decimal(39,0) unsigned
Null: NO
Key:
Default: 0
Extra:
*************************** 4. row ***************************
Field: subnet
Type: int(4)
Null: NO
Key:
Default: NULL
Extra:

Now, I run a simple SELECT statement against the "id" column:

mysql> SELECT id FROM ipspace6 WHERE id='50552019118453823914642686339427860480';
+----------------------------------------+
| id |
+----------------------------------------+
| 50552019118453823730175245602332344320 |
| 50552019118453823730175245602332344320 |
| 50552019118453823914642686339427860480 |
| 50552019118453823914642686339427860480 |
+----------------------------------------+

...What the heck is going on here? Two of these results are valid, and two definitely are not.

It's not like I'm doing some super-complex nested query or anything, this is simple stuff, and it's driving me insane.

Help, anyone?

2 Answers 2

3

Remove the quotes. When you operate with any kind of numerics you should always use numbers, not strings.

Sign up to request clarification or add additional context in comments.

3 Comments

+1, can reproduce problem with quotes, no problem without. Probably casting string to integer instead of decimal for comparison.
Accepted answer, this is exactly what was wrong. I had no idea that MySQL would do that with single-quotes. Thanks!
>> Probably casting string to integer instead of decimal for comparison --- actually mysql is trying to cast the field to the expression it compared to, not vice versa. That's why id = '42' (where id is an integer) can often be the cause of the performance degradation.
2

Did you try passing "id" not as a string but as a numeric value?

1 Comment

i was across internet searching why my query didnt work, it was the casting, i was sending numbers as strings

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.