使用CASE语句时,子字符串的结果不起作用

问题描述

列的类型:jsonb

这里的数据:

enter image description here

现在我想将 2.5kg 转换为 2500 。并删除其余子字符串。

此处查询

select id,case when title_en ~ 'kg$' 
    then 
        cast(replace(substring(title_en 
        from 
        (length(title_en) - position(' ' in reverse(title_en)) + 1) -- last space position
        for 
        (position('kg' in title_en)) - (length(title_en) - position(' ' in reverse(title_en)) + 1) -- count of chars to extract
                 ),','.')::float * 1000 as text)
    else title_en
    end,weight_qty,options_weight from result_table

我将所有列都转换为文本类型。 结果如下:

enter image description here

好。这是正确的结果。现在,我需要在 title_zh_CN

列中过滤记录内容 2500

我尝试这样做(仅显示 where 子句)

weight_qty,options_weight from result_table
where  
title_en ~ '2500'

但是结果为空。

但是,如果我尝试使用旧值( 2.5kg )超过其正确值,则显示一条记录。

weight_qty,options_weight from result_table
where  
title_en ~ '2.5kg'

结果:

enter image description here

为什么不使用新值( 2500 )?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)