如何解析字典对象,其中value也是bigquery表中的字典?

时间:2018-04-17 18:33:08

标签: google-bigquery

我的表格中有一列有此值

  

{" 10037" {" ID":" 10550""名称":"原&#34 ;, "指数":0}," 10403" {" ID":" 104470""名称":& #34;原""指数":0}," 105852" {" ID":" 10608"&# 34;名称":"成功""指数":1}," 1052" {" ID":&#34 ; 105993"," name":" Promo"," index":0}}

我想要获得所有"名称"

1 个答案:

答案 0 :(得分:3)

以下是BigQuery Standard SQL

   
#standardSQL
WITH `project.dataset.your_table` AS (
  SELECT 1 obj_id, '{"10037":{"id":"10550","name":"Original","index":0},"10403":{"id":"104470","name":"Original","index":0},"105852":{"id":"10608","name":"Success","index":1},"1052":{"id":"105993","name":"Promo","index":0}}' AS object
)
SELECT obj_id, name
FROM `project.dataset.your_table`, 
UNNEST(REGEXP_EXTRACT_ALL(object, r'"name":"(\w+)"')) name

结果为

Row obj_id  name     
1   1       Original     
2   1       Original     
3   1       Success  
4   1       Promo