I currently have an MySQL (Aurora MySQL based on MySQL 5.7.x) PROCEDURE
that takes a stringified list of ids as TEXT
and uses a CONCAT
function to create a prepared statement for execution.
While the procedure works most of the time, I am getting truncation errors on a few calls to it (likely that have a lot of IDs). The error message is essentially:
com.mysql.jdbc.MysqlDataTruncation Data truncation: Data too long for column 'stuffIds' at row 1
My initial thought was that we had selected too small of a type for the PROCEDURE
param stuffIds
, but when I checked, I discovered it's type is TEXT
. It seems REALLY unlikely that our service is maxing out that type, which to my knowledge is limited at 2^31 chars (or 2GB of data). We just don't have enough IDs in any list to hit that limit.
My next thought was that maybe it's related to the CONCAT
function that we're using to create the prepared statement? But while I've seen lots of issues & answers around GROUP_CONCAT
and its max length (and the related configs), I have not been able to locate any info on the max length of string supported by MySQL's CONCAT
function.
The only thing left I could think of was that maybe it's related specifically to AWS Aurora's implementation of MySQL? I think Aurora is supposed to be pretty close to vanilla MySQL, but maybe this is an edge case?
The PROCEDURE
itself (the names have been changed to protect the innocent) raising this error looks like:
DELIMITER //
CREATE PROCEDURE GetThingsByStuffIds(stuffIds TEXT)
BEGIN
SET @stmt = CONCAT('SELECT ThingId FROM ThingTable WHERE StuffId IN (', stuffIds, ')');
PREPARE insert_stm FROM @stmt;
EXECUTE insert_stm;
DEALLOCATE PREPARE insert_stm;
END //
DELIMITER ;
Any insights are appreciated. Thanks!
UPDATE/NOTE/WARNING!
As @Schwern pointed out, I had my MySQL TEXT
type info wrong!
which to my knowledge is limited at 2^31 chars (or 2GB of data)
That part of my question was very incorrect! Unlike PostgreSQL, as @Schwern states below, MySQL has three sized variants of TEXT
- TEXT
(65,535 chars), MEDIUMTEXT
(16,777,215 chars), LONGTEXT
(4,294,967,295 chars). I misunderstood the length limits of TEXT
, hence why my call was exceeding the limits. The full info on these types in MySQL is here. Adding this note so my misinformation in the question doesn't mislead anyone!