I've got a simple table with several columns and I'm trying to merge two of them into one. I'm working with MySQL 5.5 and I can reproduce the error one a specific data set by running the following (anonymized) query through MySQL Workbench:
UPDATE person SET a = CONCAT_WS('\n', a, b)
It clearly produces the following response message:
Error Code: 1406. Data too long for column 'a' at row 34
Because both a
and b
are VARCHAR(200)
the response is fair, but I would expect and hope that since it produced an error, no changes would be commited. However, apparently it does. I'm not able to reproduce it on a smaller dummy dataset. I am using auto commit.
Am I simply wrong in my assumption that erronous queries don't change any values? Could it be some feature of either auto commit, or other setup of my MySQL server?
Please ask if any obvious detail is missing from my specification.
Best Answer
The reason is in Strict SQL mode.
When error (instead of warning) occures, only the rest of rows is ignored, rows already updated do not ROLLBACKed.
See Strict SQL Mode:
It is a statement which affects strictly one row. By WHERE conditions and/or by LIMIT borders. If warning converted to error occures, the row in update is not altered.
This means that concatenated value can be up to 402 symbols. So use
or