Sample Header Ad - 728x90

MySQL randomly inserts a string as decimal into varchar column

0 votes
0 answers
57 views
We have encountered rather weird behavior which is very hard to reproduce. When inserting specific **strings that resemble scientific notation** into a varchar column, it would be inserted as 65 of 9 which would indicate an overflow, meaning, that our string is randomly being inserted as a decimal which is way too big. Another weird part of this is that even with a same string, behavior varies. Most of the time, it would be inserted properly, yet on some occasions the very same string would be inserted as 99999999999999999999999999999999999999999999999999999999999999999. Example of incorrectly inserted values 4840e430eac9f22a5e8609a1c95faaeb8c921f66e24e55cf839a00eb35790c00 2e540795-afe5-4644-a3d0-2aaae007c76e These values are inserted into columns that were created with either
columnName varchar(510) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL
or
columnName varchar(1022) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL
We have determined the issue **likely** to be on the side of MySQL, rather than Laravel or ProxySQL, as query being sent to MySQL is like this (according to query logs produced by Laravel and ProxySQL). Below is an example of a query from taken directly from said log.
insert into table1 (irrelevantColumn, columnName, UUID) 
values (
 'someString', 
 '4840e430eac9f22a5e8609a1c95faaeb8c921f66e24e55cf839a00eb35790c00', 
 '2e540795-afe5-4644-a3d0-2aaae007c76e'
)
We would like to determine what causes this behavior and how it can be prevented. Stack used: - Laravel 11 + Octane (strict mode enabled in the config) - ProxySQL 2.7.1 - AWS RDS MySQL version: 8.0.35, Engine being used is InnoDB Laravel starts a session with the following parameters `SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_ci', time_zone='+00:00', SESSION sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'`
Asked by Igor Yavych (97 rep)
Feb 5, 2025, 09:42 AM
Last activity: Feb 5, 2025, 02:58 PM