比较要在BigQuery中返回布尔值的整数

问题描述:

运行大查询选择大小写当从命令行进行查询时。查看字符串时,如果要查看数字值并将其转换为整数 - 需要将其与一个值进行比较并返回布尔值,以便case语句正常工作。比较要在BigQuery中返回布尔值的整数

bq query SELECT case when integer(right(strWithNumb,8))> 10000000 then right(strWithNumb,8) else "no" end FROM [Project:bucket.mytable] 

返回

“CASE预计当表达式为布尔”。

我想:

boolean(integer(right(strWithNumb,8))> 10000000) 

,但得到

“期待: ”当“ ...”

即使你的原始查询在Web UI的工作 - 它在bq命令行工具中失败取决于您的环境 - 例如,如果您在PC上

尝试转义>字符与^并包含整个查询与",如下面的示例中所示。请注意,也"no"

bq query "SELECT case when integer(right(strWithNumb,8)) ^> 10000000 then right(strWithNumb,8) else \"no\" end FROM [Project:bucket.mytable]" 

逃逸"就可以避免以后通过改变"'

bq query "SELECT case when integer(right(strWithNumb,8)) ^> 10000000 then right(strWithNumb,8) else 'no' end FROM [Project:bucket.mytable]" 

多一点的解释:

当您执行原来的命令(在PC机例如通过Google Cloud SDK Shell)您的实际查询变成如下

SELECT case when integer(right(strWithNumb,8)) then right(strWithNumb,8) else "no" end FROM [Project:bucket.mytable] 

正如你所看到的查询您> 10000000部分丢失从而使WHEN表达INTEGER而不是预期BOOLEAN

希望这有助于

+0

非常有帮助谢谢 –