I am trying to select numeric part of string and find a maximum from it. I write this code, but something goes wrong, when i added CHARINDEX function.
Integer sss= (Integer) em.createQuery("SELECT max(cast(SUBSTRING(s.fam, 1, CHARINDEX('-',s.fam)-1) as integer)) FROM Teacher s").getSingleResult();
It gives me:
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.postgresql.util.PSQLException: ERROR: Syntax error (approximately position: "as")
I got the same with PATINDEX and LOCATE functions.