Stephan
Stephan

Reputation: 131

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

Upvotes: 0

Views: 3053

Answers (1)

Adrian Klaver
Adrian Klaver

Reputation: 19664

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

Upvotes: 1

Related Questions