2

When Im trying to call JPA function this statement I got an error: syntax error at or near ":"

 public interface BcaTestRepository extends CrudRepository<InBodyBCA, Long> {
  @Query(value = "SELECT * FROM in_body_bca bca WHERE person_id = :personId " +
      "AND to_timestamp(bca.datetimes::text, 'YYYYMMDDHH24MISS')  BETWEEN :startRange AND :endRange",
      nativeQuery = true)
  List<InBodyBCA> findAllByPersonId(@Param("personId") Long personId,
                                    @Param("startRange") LocalDateTime startRange,
                                    @Param("endRange") LocalDateTime endRange);

But in PgAdmin the query works fine

SELECT id, to_timestamp(datetimes::text, 'YYYYMMDDHH24MISS') as dt FROM in_body_bca WHERE to_date(datetimes::text, 'YYYYMMDDHH24MISS')
BETWEEN '2018-05-07' AND '2019-05-07' ORDER BY to_date(datetimes::text, 'YYYYMMDDHH24MISS') DESC ;
1
  • What data type is bca.datetimes? Casting to text combined with to_timestamp() doesn't really make sense. What are you trying to do there? Commented Jul 11, 2019 at 9:47

1 Answer 1

4

You use the double colon here: bca.datetimes::text. JPA would look for text variable name.

You need to escape it:

bca.datetimes\\:\\:text
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry! It actually did help! Thank you!
@user3693537: Alternatively: cast(bca.datetimes as text)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.