I tried a workaround method that is CONCAT for a row and returns it in JSON and updates the table. This is not the most elegant way, so if you have any suggestions, please let me know! :)
BEGIN DECLARE var1 INT default -2; //offsets DECLARE var2 INT default 2; //offsets SELECT StatusID into @statusList FROM UserStatusesIndex; SET @statusID_to_remove = OLD.StatusID; SET @startIndex = INSTR(@statusList, @statusID_to_remove); SET @charLength = CHAR_LENGTH(@statusID_to_remove); IF @startIndex <= 2 THEN SET var1=-1, var2=2; //If its the first index ELSEIF (CHAR_LENGTH(@statusList) - @startIndex <= 2) THEN SET var1=-3, var2=0; //If its the last index ELSE SET var1=-2, var2=2; END IF; SET @newJson=CAST(CONCAT(SUBSTRING(@statusList, 1, @startIndex+var1), SUBSTR(@statusList, @startIndex + @charLength+var2, CHAR_LENGTH(@statusList) - @startIndex - @charLength+2)) as JSON); UPDATE UserStatusesIndex SET StatusID=@newJson WHERE StatusCreator=OLD.StatusCreator; END
Thanks!
source share