Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery - DATE_TRUNC error

trying to get the monthly aggregated data from Legacy table. Meaning date columns are strings:

amount  date_create
100     2018-01-05
200     2018-02-03
300     2018-01-22

However, the command

 Select DATE_TRUNC(DATE date_create, MONTH) as month, 
        sum(amount) as amount_m 
 from table  
 group by 1

Returns the following error:

Error: Syntax error: Expected ")" but got identifier "date_create"

Why does this query not run and what can be done to avoid the issue?

Thanks

like image 740
Ilja Avatar asked Mar 03 '26 07:03

Ilja


1 Answers

It looks like you meant to cast date_create instead of using the DATE keyword (which is how you construct a literal value) there. Try this instead:

Select DATE_TRUNC(DATE(date_create), MONTH) as month, 
    sum(amount) as amount_m 
from table
GROUP BY 1
like image 182
Elliott Brossard Avatar answered Mar 05 '26 07:03

Elliott Brossard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!