表中的数组类型?

时间:2016-08-08 19:11:07

标签: google-bigquery

我的数据包含一列和JSON格式的ID数组。

"100,101,102"

我希望能够查询类似

的行
WHERE "101" IN idarray

但似乎不支持ARRAY类型作为列类型。

BigQuery中是否有一种方法可以查询包含元素的数组或分隔字符串?

例如在PostgreSQL中,我可以使用数组contains元素语法 @>

1 个答案:

答案 0 :(得分:2)

SELECT *
FROM (
SELECT idarray FROM
  (SELECT "100,101,102" AS idarray),
  (SELECT "200,201,202,1010" AS idarray),
) as YourTable
WHERE "," + idarray + "," CONTAINS "," + "101" + ","

与上述相同,但“采用”BigQuery Standard SQL

WITH YourTable AS (
  SELECT "100,101,102" AS idarray UNION ALL
  SELECT "200,201,202,1010" AS idarray
)
SELECT *
FROM YourTable
WHERE CONCAT(",", idarray, ",") LIKE CONCAT("%,", "101", ",%")

WITH YourTable AS (
  SELECT "100,101,102" AS idarray UNION ALL
  SELECT "200,201,202,1010" AS idarray
)
SELECT *
FROM YourTable
WHERE REGEXP_CONTAINS(idarray, r"\b101\b")

或(“纯”标准SQL样式)

WITH YourTable AS (
  SELECT "100,101,102" AS idarray UNION ALL
  SELECT "200,201,202,1010" AS idarray
)
SELECT idarray
FROM YourTable, UNNEST(SPLIT(idarray)) AS id1
WHERE id1 = "101"