Created
December 10, 2013 22:57
-
-
Save brianroth/7901930 to your computer and use it in GitHub Desktop.
Initializer to patch Arel to properly break apart IN clauses with more than 1000 values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Arel | |
module Visitors | |
class Oracle < Arel::Visitors::ToSql | |
private | |
def visit_Array o | |
if o.empty? | |
'NULL' | |
else | |
listtype = o[0].to_s =~ /\D/ ? 'odcivarchar2list': 'odcinumberlist' | |
quoted_chunks = o.in_groups_of(999, false).map do |chunk| | |
"(SELECT * FROM TABLE(sys.#{listtype}(#{chunk.map { |x| visit x }.join(', ')})))" | |
end | |
quoted_chunks * " UNION " | |
end | |
end | |
end | |
end | |
end if USE_RAILS_3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment