Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Syntax error for Where clause in Bigquery

I am getting an error when I try to use where clause in the following query :

SELECT  
  creation_date
FROM 
  `bigquery-public-data.stackoverflow.stackoverflow_posts`
WHERE
  creation_date BETWEEN 2021-08-01 AND 2021-08-31;

Syntax error : No matching signature for operator BETWEEN for argument types: TIMESTAMP, INT64, INT64.  Supported signature: (ANY) BETWEEN (ANY) AND (ANY) at [6:17] 

What is the correct way to do it? I am trying to create daily aggregate table for month of August combing data from 2 tables.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just look at the actual data types you are dealing with: following will work: creation_date is timestamp data type so cast to DATE and use quotes for static dates.

SELECT  
  creation_date
FROM 
  `bigquery-public-data.stackoverflow.stackoverflow_posts`
WHERE
  DATE(creation_date) BETWEEN '2013-01-02' AND '2021-08-31';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading