如何提取 Google BigQuery 中字符串列中的所有(包括 int 和 float)数值?

How to extract all (including int and float) numerical values in a string column in Google BigQuery?

我在 Google BigQuery 上有一个 table Table_1,其中包含一个字符串列 str_column。我想编写一个 SQL 查询(与 Google BigQuery 兼容)以提取 str_column 中的所有数值并将它们作为新的数字列附加到 Table_1。例如,如果 str_column 包含 first measurement is 22 and the other is 2.5;我需要提取 22 和 2.5 并将它们保存在新列 numerical_val_1numerical_val_2 下。理想情况下,新数值列的数量应等于 str_column 中数值的最大数量,但如果那样太复杂,则提取 str_column 中的前 2 个数值(因此 2 个新数值列)也可以。有什么想法吗?

考虑以下方法

select * from (
  select str_column, offset + 1 as offset, num
  from your_table, unnest(regexp_extract_all(str_column, r'\b([\d.]+)\b')) num with offset
)
pivot (min(num) as numerical_val for offset in (1,2,3))    

如果应用于您问题中的示例数据 - 输出为