我想从数据库的text列中获取数字(例如,下一个文本是'Test 900 test')
select substring('Test 900 g' from '[0-9]+\.?[0-9]*')文本中的数字可以是浮点数(从0到1),也可以是整数(>100),我想用下面的方式使用CASE将其转换为单一浮动格式
select case when substring('Test 900 g' from '[0-9]+\.?[0-9]*')::numeric >= 100
then substring('Test 900 g' from '[0-9]+\.?[0-9]*')::numeric / 10000
else substring('Test 900 g' from '[0-9]+\.?[0-9]*')::numeric
end as single_formatPostgres是每次在这个CASE构造中重新计算子字符串值,还是对每一行只进行一次优化和计算?
发布于 2021-12-07 18:07:44
不容易回答您的查询。
表达式只应在以下查询中计算一次:
select case
when num >= 100
then num / 10000
else num
end as single_format
from CAST(substring('Test 900 g' from '[0-9]+\.?[0-9]*') AS numeric) AS numhttps://stackoverflow.com/questions/70263679
复制相似问题