bq command-line tool: query fails when text includes “ > ” or “ < ”

帅比萌擦擦* 提交于 2021-01-29 04:24:10

问题


I'm having problems using the bq command-line tool to run queries that contain a > or < symbol.

The first two examples below show that when I try to select rows from a table where id > 300 nothing is returned, yet when I select for id=301 I get a result.

The second two examples show that when I try to select rows where id < 300 I get a syntax error, but when I select for id=299 I get a result.

Does anyone know why this is happening and how to fix it?

Many thanks,

Steve

C:\Users\stephen.caruana>bq query "SELECT sk_id from test.test_1 WHERE id > 300 LIMIT 5" Waiting on bqjob_r56794831_000001585450df31_1 ... (0s) Current status: DONE

C:\Users\stephen.caruana>bq query "SELECT sk_id from test.test_1 WHERE id = 301 LIMIT 5" Waiting on bqjob_r03e25be0_0000015854521a94_1 ... (3s) Current status: DONE +-------+ | sk_id | +-------+ | 301 | +-------+

C:\Users\stephen.caruana>bq query "SELECT sk_id from test.test_1 WHERE id < 300 LIMIT 5" Waiting on bqjob_r1615cc38_000001585451837a_1 ... (0s) Current status: DONE Error in query string: Error processing job 'itg-creator-lgi-ecrm:bqjob_r1615cc38_000001585451837a_1': WHERE clause is not a boolean expression (found int64)

C:\Users\stephen.caruana>bq query "SELECT sk_id from test.test_1 WHERE id = 299 LIMIT 5" Waiting on bqjob_r7e6824a9_000001585452ba30_1 ... (2s) Current status: DONE +-------+ | sk_id | +-------+ | 299 | +-------+


回答1:


It's a Windows command prompt issue. You need to escape the ">" and "<" symbols with "^", otherwise command prompt thinks it's a redirect of the output. So your command should look like

bq query "SELECT sk_id from test.test_1 WHERE id ^> 300 LIMIT 5"



来源:https://stackoverflow.com/questions/40552907/bq-command-line-tool-query-fails-when-text-includes-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!