Guest User

Untitled

a guest
Jun 22nd, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. update my_table t1
  2. set my_index_column = t2.rownum
  3. from (
  4. select id, row_number() over (order by my_index_column asc) - 1 as rownum
  5. where id = 1
  6. ) as t2
  7. where t1.id = t2.id;
  8.  
  9. import static org.jooq.impl.DSL.*;
  10.  
  11. public class MyQueryExecutor {
  12.  
  13. private final DSLContext jooq; // this gets set via dependency-injection
  14.  
  15. public void doTheUpdate(String id) {
  16.  
  17. jooq.update(table("my_table").as("t1")).set(
  18. field("my_index_column"), field("t2.rownum")
  19. ).from(
  20. jooq.select(field("id"), (rowNumber().over(orderBy(field("my_index_column").asc())).minus(1)).as("rownum"))
  21. .from(table("my_table"))
  22. .where(field("id").eq(id))
  23. ).as("t2") // <-- this is the line that doesn't work
  24. .where(field("t1.id").eq(field("t2.id")))
  25. .execute();
  26. }
  27. }
Add Comment
Please, Sign In to add comment