BETWEEN '2010-10-01' AND '2010-10-31' RETURNING * ) INSERT INTO products_log SELECT * FROM moved_rows; DB[:products_log]. with(:moved_rows, DB[:products]. where(date: Date.new(2010, 10, 1)..Date.new(2010, 10, 31)). returning. with_sql(:delete_sql)). insert(DB[:moved_rows])