Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery modulo operator (%) does not work in WHERE clause

When I used modulo operator (%) in WHERE clause on BigQuery,

SELECT * from `our-project.data_set1.table1` WHERE the_id % 10 = 0 LIMIT 1000

it was rejected with the error message like as;

Error: Syntax error; Illegal input character "%" at [1:50]

I made the turn-around like,

SELECT * from `our-project.data_set1.table1` 
WHERE CAST((the_id / 10) AS INT64) * 10 = the_id LIMIT 1000

However, it seems to be wasteful.

How can I use modulo operation in BigQuery's WHERE clause?

(In this example, I wrote in Standard SQL Dialect)

like image 384
HirofumiTamori Avatar asked Oct 26 '17 10:10

HirofumiTamori


1 Answers

Try mod(id, 10) = 0 instead in the where clause

like image 152
Ab Bennett Avatar answered Oct 19 '22 22:10

Ab Bennett