Advertisement
caps_lock

mig2

Jan 29th, 2019
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. irb(main):036:0> batch = Booking.where.not(token:nil, reseller_voucher:nil).order("id ASC").offset(offset).limit(limit)
  2. Booking Load (517.4ms) SELECT "bookings".* FROM "bookings" WHERE ("bookings"."token" IS NOT NULL) AND ("bookings"."reseller_voucher_id" IS NOT NULL) ORDER BY id ASC LIMIT 10000 OFFSET 1900000
  3. => #<ActiveRecord::Relation []>
  4. irb(main):037:0> batch.update_all(from_reseller_voucher: true)
  5. SQL (3839.7ms) UPDATE "bookings" SET "from_reseller_voucher" = 't' WHERE "bookings"."id" IN (SELECT "bookings"."id" FROM "bookings" WHERE ("bookings"."token" IS NOT NULL) AND ("bookings"."reseller_voucher_id" IS NOT NULL) ORDER BY id ASC LIMIT 10000)
  6. => 10000
  7. irb(main):038:0> updated_count = Booking.connection.update_sql(%Q[
  8. irb(main):039:1" UPDATE bookings
  9. irb(main):040:1" SET from_reseller_voucher = true
  10. irb(main):041:1" FROM (
  11. irb(main):042:1" SELECT bookings.id FROM bookings
  12. irb(main):043:1" WHERE token IS NOT NULL AND reseller_voucher_id IS NOT NULL
  13. irb(main):044:1" LIMIT #{limit} OFFSET #{offset}
  14. irb(main):045:1" ) as bookings_to_update
  15. irb(main):046:1" WHERE bookings_to_update.id = bookings.id
  16. irb(main):047:1" ])
  17. (787.0ms)
  18. UPDATE bookings
  19. SET from_reseller_voucher = true
  20. FROM (
  21. SELECT bookings.id FROM bookings
  22. WHERE token IS NOT NULL AND reseller_voucher_id IS NOT NULL
  23. LIMIT 10000 OFFSET 1900000
  24. ) as bookings_to_update
  25. WHERE bookings_to_update.id = bookings.id
  26.  
  27. => 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement