无法在SELECT上使用CAST AS RECORD

时间:2019-02-26 11:55:29

标签: string casting google-bigquery

我有一个包含2列的简单表:Col1和Col2

> legend(0.2,0.1, avector, col=col_vector, pch=15, ncol = 3, cex=1)
Error in strwidth(legend, units = "user", cex = cex, font = text.font) : 
  invalid graphics state

此查询工作正常

sh-3.2# ./bq show --schema dataset.Test
[{"type":"STRING","name":"Col1","mode":"NULLABLE"},{"type":"STRING","name":"Col2","mode":"NULLABLE"}]

此查询返回错误

SELECT * EXCEPT (Col2) , CAST(Col2 AS NUMERIC) AS Col2 FROM `project.dataset.Test` LIMIT 1000

有什么想法吗?

我正在尝试使用WebUI中出现的关键字RECORD

enter image description here

1 个答案:

答案 0 :(得分:1)

BigQuery转换规则不允许您从字符串转换为记录(AKA结构)。

https://cloud.google.com/bigquery/docs/reference/standard-sql/conversion_rules

您将不得不在查询中自行构造该结构。像这样:

SELECT 
    * EXCEPT (Col2), 
    STRUCT( Col2 as inner_Col2) as my_inner_record 
FROM `project.dataset.Test` LIMIT 1000