I'm trying to get all rows associated with a particular entity ID over the last week. Each row has a timestamp. I'd like to group those entities by day, by extracting the date from the datetime timestamp, but when I try, I get
Error: (L6:28): expression STRFTIME_UTC_USEC([data_timestamp], '%Y-%m-%d') in GROUP BY is invalid
from bigquery. It appears as though something is wrong with the DATE() function.
Here is the full query I am running:
SELECT Count(*) FROM [myproj:mydataset.mytable]
WHERE
bool_property=False
AND
entity_id=5667423172689920
AND
DATEDIFF(CURRENT_DATE(), data_timestamp) <= 7
GROUP BY DATE(data_timestamp)
Looking at the data, it would appear that the quality, here called 'data_timestamp' is in fact a proper timestamp; I really don't understand why the DATE() function would be failing.
Any help or tips? Thanks!