如何CAST / REPLACE NESTED表从FLOAT更改为NUMERIC

时间:2019-07-15 08:15:20

标签: google-bigquery

问题:我已经嵌套了表格,但是现在我需要将某些列的格式从FLOAT更改为NUMERIC,解决此问题的最佳方法是什么?

这是我尝试过的(到目前为止最好的主意)

SELECT * 
REPLACE(ARRAY(SELECT AS STRUCT CAST(OL.VAT AS NUMERIC) FROM UNNEST(OrderLines) OL) AS VAT)

但这仍然行不通,因为它只是创建一个字段-VAT._field_1

也可以这样进行:但是它将替换值,而不是嵌套表中的值

SELECT D.*
REPLACE(CAST(UOL.VAT AS NUMERIC) AS VAT)
FROM D, UNNEST(OrderLines) AS UOL

2 个答案:

答案 0 :(得分:1)

您可以直接在select as struct内做别名

SELECT * EXCEPT(OrderLines),
ARRAY(SELECT AS STRUCT CAST(OL.VAT AS NUMERIC) AS VAT FROM UNNEST(OrderLines) OL) AS OrderLines

答案 1 :(得分:0)

基本上,这就是答案

SELECT * REPLACE(ARRAY(SELECT AS STRUCT * REPLACE(CAST(VATAS NUMERIC) AS VAT) FROM UNNEST(OrderLines) ol) AS OrderLines)
FROM A