UPDATE tblemailqueuebak SET title = REPLACE( title, ‘{coinkind}’,…
- User
UPDATE tbl_email_queue_bak SET title = REPLACE( title, ‘{coinkind}’, IFNULL(parameter->‘$.coinkind’, ‘’) ) WHERE email_template_id = 2007 报错Invalid JSON text in argument 1 to function json_extract: “Invalid encoding in string.” at position 693.
- Assistant
The error message suggests that there is an issue with the JSON text in the argument of the json_extract function at position 693. It seems that there might be an invalid encoding in the string.
To resolve this error, you can try modifying the JSON text in the parameter->‘$.coinkind’ part of your query. Make sure that the JSON string is properly encoded and valid. Additionally, check if there are any special characters or invalid characters causing this issue and correct them if necessary.
Here is an updated version of the query:
UPDATE tbl_email_queue_bak SET title = REPLACE( title, '{coinkind}', IFNULL(parameter->'$.coinkind', '') ) WHERE email_template_id = 2007
- User
UPDATE tbl_email_queue_bak SET title = REPLACE( title, ‘{coinkind}’, IFNULL(parameter->‘$.coinkind’, ‘’) ) WHERE email_template_id = 2007 出现报错Invalid JSON text in argument 1 to function json_extract: “Invalid encoding in string.” at position 693.
- Assistant
I apologize for the confusion. It seems like the issue still persists. The error message indicates that there is an invalid encoding in the JSON string at position 693.
To resolve this error, you need to ensure that the JSON string in the parameter->‘$.coinkind’ part of the query is properly encoded and does not contain any invalid characters or formatting.
Here is an updated version of the query with potential fixes:
UPDATE tbl_email_queue_bak SET title = REPLACE( title, '{coinkind}', IFNULL(JSON_UNQUOTE(JSON_EXTRACT(parameter, '$.coinkind')), '') ) WHERE email_template_id = 2007
This query uses the JSON_UNQUOTE and JSON_EXTRACT functions to extract the coinkind value from the parameter JSON field. It then replaces the '{coinkind}' placeholder in the title column with the extracted value, or an empty string if the value is null.
Make sure to verify that the JSON string is correctly formatted and encoded in the parameter field.
- User
mysql有的json字段存在,有的不存在,我要怎么取出来,而不会报错
- Assistant
如果您使用的MySQL版本支持JSON类型,您可以使用MySQL的JSON函数来处理可能不存在的JSON字段。
要避免报错并获取JSON字段的值,您可以使用JSON_EXTRACT函数结合JSON_VALID函数来判断字段是否存在,如下所示:
SELECT JSON_EXTRACT(parameter, '.coinkind') IS NOT NULL