如何通过CAST更改BigQuery中的嵌套字段的类型?

时间:2019-03-05 12:22:28

标签: google-bigquery

我正在尝试从查询中创建一个新表,在此过程中强制转换嵌套字段之一。 像这样:

#standardSQL    
SELECT * EXCEPT (bid_info),
  (SELECT AS STRUCT bid_info.* EXCEPT (clicks), CAST(bid_info.clicks AS NUMERIC) as clicks 
  FROM `testing.fb_ads.ads`) as bid_info
FROM `testing.fb_ads.ads`

我收到错误消息“标量子查询产生了多个元素”,并且查询执行似乎没有结束。

如何解决此查询?

1 个答案:

答案 0 :(得分:1)

所以,我毕竟找到了解决方案,就可以了:

SELECT * EXCEPT (bid_info),
(SELECT AS STRUCT bid_info.* EXCEPT (clicks), CAST(bid_info.clicks AS NUMERIC) as clicks ) as bid_info
FROM `testing.fb_ads.ads`