79669739

Date: 2025-06-17 21:02:44
Score: 0.5
Natty:
Report link

As Barmar mentioned: '15b' cannot be converted to an integer. The SELECT is done, but with a warning. The UPDATE leads to an error. I have to cut of the 'b' before. My field contains 2 patterns of not convertable strings: '15b' or '02, 03'. I am only interested in the digits at the begin: '15b' => 15, '02, 03' => 2. So I had to cut of everthing behind:

UPDATE product_translation
SET custom_fields = JSON_INSERT(custom_fields, '$."sorting"', CAST(REGEXP_SUBSTR(JSON_EXTRACT(custom_fields, '$."product_attr4"'), '[0-9]+') AS SIGNED))
WHERE JSON_CONTAINS_PATH(custom_fields, 'one', '$."product_attr4"') 
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Roman Walters