I have the following Oracle SQL query:
SELECT user FROM global_users user WHERE user.status = 'ACTIVE'
AND user.description IS NOT NULL AND user.updatedGoodsDate BETWEEN '2024-03-10 20:09:53' AND '2024-03-10 20:09:53'
AND ROWNUM <= 13
I tried to edit the query into Postgres with Spring Data JPA:
@Query("SELECT user FROM global_users user WHERE user.status = :status
AND user.description IS NOT NULL AND user.updatedGoodsDate BETWEEN :startDate AND :endDate")
List<Users> findTopUsers(@Param("status") TransactionStatus status,
@Param("startDate") OffsetDateTime start, @Param("endDate") OffsetDateTime end, @Param("count") long count);
But I can't use LIMIT clause in Postgre. Is there some way to edit the query and get the same result?
For example can this be implemented with a subquery?
From Oracle 12 and, at least PostgreSQL 9, both RDBMS support the
FETCH FIRST n ROWS ONLYsyntax:Which, for the sample data:
Outputs:
Oracle fiddle PostgreSQL fiddle