简体   繁体   中英

date_trunc function in jpql query

I am really stuck with date_trunc funtion in JPQL.

My query is:

@Query("SELECT c.name AS name, SUM(c.salary) AS salary FROM SalaryTable AS c GROUP BY c.name, date_trunc('year' c.savedtimestamp)") 

I get the exception:

has 'date_trunc' and '('year' c.savedtimestamp)' that are not separated by a comma.\n[197, 203] The identification variable ''year'' is not following the rules for a Java identifier.","\tat org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:157)","\tat org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:336)","\tat org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:280)","\tat

Can you help me in this regard?

Regards, Stephan

Should be:

date_trunc('year', c.savedtimestamp)

Note the ',' per the error message"

has 'date_trunc' and '('year' c.savedtimestamp)' that are not separated by a comma

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM