ClickHouse JSON 解析

使用场景

DB::Exception: Unknown function JSON_EXTRACT. Maybe you meant: ['JSONExtract','JSONExtractRaw']: While processing audit_id, credit_id, order_id, product_code, strategy_code, multiIf(substring(strategy_code, -2) = '02', 'UC', 'GC') AS audit_phase, name AS real_name, upper(id_no) AS certificate_no, bank_card_no, mobile_no, JSON_EXTRACT(ext_param_json_str, '$.applyAmount') AS apply_limit, audit_status, replaceAll(reason_code, ',', ';') AS reason_code, replaceAll(reason_desc, ',', ';') AS reason_desc, result_time, approval_mark, 'anjuke_loan' AS source_db, created_time, updated_time. 2025-07-10 16:34:03 [com.xxl.job.core.thread.JobThread#run]-[164]-[Thread-24468]

将mysql 迁移至 ClickHouse 遇到JSON 报错

mysql

解决方案

使用 JSONExtractInt

基本 JSON 解析函数

-- 提取字符串

SELECT JSONExtractString('{"name":"张三","age":25}', 'name') AS name;

-- 提取整数

SELECT JSONExtractInt('{"name":"张三","age":25}', 'age') AS age;

-- 提取浮点数

SELECT JSONExtractFloat('{"price":99.99}', 'price') AS price;

-- 提取布尔值

SELECT JSONExtractBool('{"active":true}', 'active') AS is_active;