Bigquery error: 400 No matching signature for operator BETWEEN for argument types: DATE, TIMESTAMP, TIMESTAMP

梦想与她 提交于 2020-06-16 04:59:19

问题


I have deployed my webapp on Google Cloud Bigquery, when I query the data I get an error "400 No matching signature for operator BETWEEN for argument types: DATE, STRING, STRING. Supported signature: (ANY) BETWEEN (ANY) AND (ANY) at [2:38]". Here is my sql:

"""SELECT 
   Record_Start_Time, Generator_Power 
FROM 
   Furnace.FurnaceData
WHERE 
   Record_Start_Time BETWEEN TIMESTAMP("2018-01-21")
AND 
  TIMESTAMP("2018-07-21") 
ORDER BY Record_Start_Time
LIMIT 100""".format(request.form['start'],request.form['end'])

回答1:


According to the error message you are getting (which, I agree with the comments in your question, is strange and I suspect does not correspond to this specific query), it looks like the field Record_Start_Time is of type DATE, while in the BETWEEN operator you are using TIMESTAMP values instead.

The way you should understand the error message you are getting, is the following:

[...] operator BETWEEN for argument types: DATE, STRING, STRING. Supported signature: (ANY) BETWEEN (ANY) AND (ANY)

This error means that the supported signature for the BETWEEN operator is field BETWEEN a AND b, where field, a and b should be of the same type (ANY). Additionally, the error message tells you that you are doing the following: _DATE_ BETWEEN _STRING_ AND _STRING_, i.e. you are trying to compare a DATE type with a STRING type. This looks strange because TIMESTAMP("2018-01-21") is of TIMESTAMP type and not STRING, but I would say that maybe you tried in the past running a query like WHERE Record_Start_Time BETWEEN "2018-01-21" AND "2018-07-21", and the error message you shared is the one corresponding to that query. For the query you shared, the error message should be:

400 No matching signature for operator BETWEEN for argument types: DATE, TIMESTAMP, TIMESTAMP. Supported signature: (ANY) BETWEEN (ANY) AND (ANY) at [2:38]

Long story short, confirm that the Record_Start_Time field is of DATE type and being that the case, change your WHERE clause to the following:

WHERE 
   Record_Start_Time BETWEEN DATE("2018-01-21")
AND 
  DATE("2018-07-21")


来源:https://stackoverflow.com/questions/51214576/bigquery-error-400-no-matching-signature-for-operator-between-for-argument-type

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