Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL wrongly updates integer column when it is updated second time

Tags:

sql

mysql

I have extremely strange problem, which drives me crazy all day. I have a simple MySQL table with few columns. One column is int(11) NULL. When I update its value, it works as expected. However, when I update its value second time, it gets assigned "0" value.

I have tested this same behaviour on my MySQL 5.1.58-1ubuntu1 and on other MySQL 5.0.96-community and both behave exactly the same. So it apparently is not problem of one version MySQL.

It is difficult for me to explain, but I have attached 2 screenshots which will tell you much better where is the better.

First screenshot is structure of my table I am updating:

table structure

And here is shown SQL queries beeing executed, where you can see, that first update is correct and the second produces "0" value in column "invoice_number" with no reason:

enter image description here

Am I overlooking something obvious ? It really drives me crazy, because it doesn't make any sense to me...

Thank you for any help in advance...

EDIT: I have tried using only numbers in my queries and this is result (very strange for me as well):

enter image description here

like image 369
Frodik Avatar asked Nov 20 '12 14:11

Frodik


People also ask

How do I find the last updated column in MySQL?

USE GEEKSFORGEEKS; Output: To have the latest updated records, we should have a column such as “last updated” with the “Timestamp” column in any table and when a record is newly inserted, it should get the current timestamp value for that column.

How UPDATE same column with different values in MySQL?

Specific columns can be modified using the SET clause by supplying new values for that column. The WHERE clause can be used to specify the conditions those identify which rows to update. Without using WHERE clause, all rows are updated. The ORDER BY clause is used to update the order that is already specified.


1 Answers

This isn't an answer, but the comments are getting crowded. The behavior you show does indicate some sort of problem, however more likely in the tool you are using to interface to the database rather than in the database.

The issue with the single quotes is a red herring (i.e. distraction). Even if '55' were interpreted differently from 55, it would be interpreted the same way in the where statement. Also, '35' worked but '30' didn't.

A key insight is the failure when you remove the quotes. The statement:

update i_orders
    set invoice_number = 30
    where id = 55

should not be looking up a column index for 30. The unknown column error you are seeing suggests that the query sent to the database is not the one you see in the tool.

Can you log the queries in the database to see what is actually being sent in?

like image 131
Gordon Linoff Avatar answered Oct 16 '22 04:10

Gordon Linoff