Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- update my_table t1
- set my_index_column = t2.rownum
- from (
- select id, row_number() over (order by my_index_column asc) - 1 as rownum
- where id = 1
- ) as t2
- where t1.id = t2.id;
- import static org.jooq.impl.DSL.*;
- public class MyQueryExecutor {
- private final DSLContext jooq; // this gets set via dependency-injection
- public void doTheUpdate(String id) {
- jooq.update(table("my_table").as("t1")).set(
- field("my_index_column"), field("t2.rownum")
- ).from(
- jooq.select(field("id"), (rowNumber().over(orderBy(field("my_index_column").asc())).minus(1)).as("rownum"))
- .from(table("my_table"))
- .where(field("id").eq(id))
- ).as("t2") // <-- this is the line that doesn't work
- .where(field("t1.id").eq(field("t2.id")))
- .execute();
- }
- }
Add Comment
Please, Sign In to add comment