The below PostgreSQL query works correct in pgAdmin.
(select * from posts where id = 1) union (select * from posts);
but when written in Spring Data JPA it doesn't work.
@Query(value = "(select * from posts where id = 1) union (select * from posts)",
nativeQuery = true)
Page<Post> getPosts(Pageable pageable);
It gives an exception
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "where"
Position: 15
i want to have a union of the two select statements but the union query is not working in JPA.