-- ============================================
-- 诊断：查看订单的地址数据
-- ============================================

-- 查看 ec_care_tasks 中这个订单的地址字段（用订单ID替换 'xxx'）
SELECT 
    id,
    task_no,
    COALESCE(address_snapshot_json::TEXT, 'NULL') AS address_snapshot_json_raw,
    COALESCE(address_snapshot::TEXT, 'NULL') AS address_snapshot_raw,
    CASE 
        WHEN address_snapshot_json IS NULL THEN 'null'
        WHEN address_snapshot_json = '{}'::jsonb THEN 'empty_object'
        ELSE 'has_data'
    END AS json_status,
    CASE 
        WHEN address_snapshot IS NULL THEN 'null'
        WHEN address_snapshot = '{}'::jsonb THEN 'empty_object'
        ELSE 'has_data'
    END AS snapshot_status
FROM public.ec_care_tasks
WHERE task_no LIKE '%20260528%'  -- 根据订单号调整
ORDER BY created_at DESC
LIMIT 5;

-- 直接测试 delivery_build_order_json 对这条数据的输出
-- SELECT delivery_build_order_json(
--     (SELECT to_jsonb(t) FROM public.ec_care_tasks t WHERE t.id = '订单UUID'::uuid),
--     '[]'::jsonb, '[]'::jsonb, '[]'::jsonb, NULL, 'care'
-- ) ->> 'address' AS test_address;
