Command line 在BigQuery中比较整数以返回布尔值
从命令行执行大查询时选择大小写查询。当在字符串中查找一个数值并将其转换为整数时,需要将其与一个值进行比较并返回一个布尔值,以便case语句能够工作Command line 在BigQuery中比较整数以返回布尔值,command-line,google-bigquery,type-conversion,Command Line,Google Bigquery,Type Conversion,从命令行执行大查询时选择大小写查询。当在字符串中查找一个数值并将其转换为整数时,需要将其与一个值进行比较并返回一个布尔值,以便case语句能够工作 bq query SELECT case when integer(right(strWithNumb,8))> 10000000 then right(strWithNumb,8) else "no" end FROM [Project:bucket.mytable] 返回 “CASE要求WHEN表达式为布尔表达式。” 我试过: boole
bq query SELECT case when integer(right(strWithNumb,8))> 10000000 then right(strWithNumb,8) else "no" end FROM [Project:bucket.mytable]
返回
“CASE要求WHEN表达式为布尔表达式。”
我试过:
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]"
您可以通过将“
更改为”
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部分丢失,从而生成
希望这有帮助