Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- irb(main):036:0> batch = Booking.where.not(token:nil, reseller_voucher:nil).order("id ASC").offset(offset).limit(limit)
- 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
- => #<ActiveRecord::Relation []>
- irb(main):037:0> batch.update_all(from_reseller_voucher: true)
- 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)
- => 10000
- irb(main):038:0> updated_count = Booking.connection.update_sql(%Q[
- irb(main):039:1" UPDATE bookings
- irb(main):040:1" SET from_reseller_voucher = true
- irb(main):041:1" FROM (
- irb(main):042:1" SELECT bookings.id FROM bookings
- irb(main):043:1" WHERE token IS NOT NULL AND reseller_voucher_id IS NOT NULL
- irb(main):044:1" LIMIT #{limit} OFFSET #{offset}
- irb(main):045:1" ) as bookings_to_update
- irb(main):046:1" WHERE bookings_to_update.id = bookings.id
- irb(main):047:1" ])
- (787.0ms)
- UPDATE bookings
- SET from_reseller_voucher = true
- FROM (
- SELECT bookings.id FROM bookings
- WHERE token IS NOT NULL AND reseller_voucher_id IS NOT NULL
- LIMIT 10000 OFFSET 1900000
- ) as bookings_to_update
- WHERE bookings_to_update.id = bookings.id
- => 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement