如何在触发器中保存json值

时间:2015-11-19 05:50:24

标签: mysql json triggers

我们创建一个触发器

CREATE TRIGGER `insert_category` AFTER INSERT ON `cleaner_service`
 FOR EACH ROW UPDATE users
  SET user_category = (select group_concat(concat(service_id) SEPARATOR '-') from cleaner_service where users.id=cleaner_service.user_id)
WHERE users.id=NEW.user_id

它存储价值如 8-7-9 这个我想将此值存储在json [" 1"," 2" ," 3"] 你能告诉我如何在 MYSQL

中做到这一点

请帮忙

1 个答案:

答案 0 :(得分:0)

尝试:

SET user_category = concat("[",(select group_concat(concat(service_id) SEPARATOR ','),"]") from cleaner_service where users.id=cleaner_service.user_id)