Skip to content

Instantly share code, notes, and snippets.

@brianroth
Created December 10, 2013 22:57
Show Gist options
  • Save brianroth/7901930 to your computer and use it in GitHub Desktop.
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
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