-- 修复错误存储的 JSON 响应，提取 answer 字段
UPDATE admin_chat_messages 
SET content = (
  -- 使用正则表达式提取 "answer":"xxx" 中的 xxx 部分
  SELECT 
    TRIM(BOTH '"' FROM 
      SUBSTRING(
        content 
        FROM '"answer"\s*:\s*"([^"]+)"'
      )
    )
)
WHERE role = 'assistant' 
  AND content LIKE '%"success":true,"answer":%'
  AND content ~ '"answer"\s*:\s*"[^"]+"';