STRING的大数组数组到INT数组

时间:2017-07-12 22:52:38

标签: google-bigquery

我正在尝试从INT64标准SQL中的BigQuery数组中删除一个由逗号分隔的长数字字符串的列(例如,2013,1625,1297,7634)。我可以使用以下方法轻松地拉出一串字符串:

SELECT
  SPLIT(string_col,",")
FROM
  table

但是,我想返回一个INT64的数组,而不是一个字符串数组。我怎样才能做到这一点?我试过了

CAST(SPLIT(string_col,",") AS ARRAY<INT64>) 

但这不起作用。

2 个答案:

答案 0 :(得分:2)

以下是BigQuery Standard SQL

  
#standardSQL
WITH yourTable AS (
  SELECT 1 AS id, '2013,1625,1297,7634' AS string_col UNION ALL
  SELECT 2, '1,2,3,4,5'
)
SELECT id, 
  (SELECT ARRAY_AGG(CAST(num AS INT64)) 
    FROM UNNEST(SPLIT(string_col)) AS num
  ) AS num,
  ARRAY(SELECT CAST(num AS INT64) 
    FROM UNNEST(SPLIT(string_col)) AS num
  ) AS num_2
FROM yourTable

答案 1 :(得分:0)

米哈伊尔打败了我,他的回答更为广泛,但将其作为一个更小的副本加入:

 <input
            type="checkbox"
             formControlName="{{country.name}}"
             (change)="search(country, $event)
                    >