How do I generate an SQL statement with a LIMIT clause but no OFFSET clause in jOOQ?

I am trying to use jOOQ to generate the following SQL statement:

SELECT id, name
FROM students
ORDER BY id DESC
LIMIT 50;

      

To generate the above statement using jOOQ:

String sql = DSL.using(SQLDialect.POSTGRES).select(
  field("id"),
  field("name"))
  .from("students")
  .orderBy(field("id").desc())
  .limit(inline(50))
  .getSQL();

      

But I am getting the following:

select id, name from students order by id desc limit 50 offset ?

      

How do I delete an offer OFFSET

? I know that I can specify an offset value of 0, the same as omitting the clause OFFSET

, but I want to know if I can completely remove it from the generated SQL statement.

Thank.

+3


source to share


1 answer


You are correct, jOOQ 3.4.2 is currently making a proposal OFFSET

for PostgreSQL, whether it was specified by users via the API or not. This can probably be improved. I created issue # 3577 for this .



There is currently no really easy way to change the generated SQL in this case. You can implement ExecuteListener

and fix the generated SQL - but you will also need to get rid of the binding value.

+2


source







All Articles