BigQuery - 将字符串转换为数字
BigQuery - Converting string to numeric
我正在寻找 RE2 接受的正则表达式语法,
将以下字符串转换为数字:
"339,840" -> 339840
“100,000 美元”-> 100000
"0.75" -> 0.75
"1" -> 1
以下适用于 BigQuery 标准 SQL
您可以使用cast(regexp_replace(val, r'[^\d.]', '') as numeric)
见下例
#standardSQL
with `project.dataset.table` as (
select "339,840" val union all
select "0,000" union all
select "0.75" union all
select "1"
)
select cast(regexp_replace(val, r'[^\d.]', '') as numeric)
from `project.dataset.table`
有输出
我正在寻找 RE2 接受的正则表达式语法, 将以下字符串转换为数字:
"339,840" -> 339840
“100,000 美元”-> 100000
"0.75" -> 0.75
"1" -> 1
以下适用于 BigQuery 标准 SQL
您可以使用cast(regexp_replace(val, r'[^\d.]', '') as numeric)
见下例
#standardSQL
with `project.dataset.table` as (
select "339,840" val union all
select "0,000" union all
select "0.75" union all
select "1"
)
select cast(regexp_replace(val, r'[^\d.]', '') as numeric)
from `project.dataset.table`
有输出