mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #211 from yahonda/support_columns_for_distinct_oracle
Support `columns_for_distinct` with Oracle adapter
This commit is contained in:
commit
2767d4a787
2 changed files with 4 additions and 3 deletions
|
@ -8,7 +8,7 @@ module Arel
|
|||
|
||||
# if need to select first records without ORDER BY and GROUP BY and without DISTINCT
|
||||
# then can use simple ROWNUM in WHERE clause
|
||||
if o.limit && o.orders.empty? && !o.offset && o.cores.first.projections.first !~ /^DISTINCT /
|
||||
if o.limit && o.orders.empty? && !o.offset && o.cores.first.set_quantifier.class.to_s !~ /Distinct/
|
||||
o.cores.last.wheres.push Nodes::LessThanOrEqual.new(
|
||||
Nodes::SqlLiteral.new('ROWNUM'), o.limit.expr
|
||||
)
|
||||
|
@ -83,7 +83,7 @@ module Arel
|
|||
return o if o.orders.empty?
|
||||
return o unless o.cores.any? do |core|
|
||||
core.projections.any? do |projection|
|
||||
/DISTINCT.*FIRST_VALUE/ === projection
|
||||
/FIRST_VALUE/ === projection
|
||||
end
|
||||
end
|
||||
# Previous version with join and split broke ORDER BY clause
|
||||
|
|
|
@ -85,7 +85,8 @@ module Arel
|
|||
|
||||
it 'creates a subquery when there is DISTINCT' do
|
||||
stmt = Nodes::SelectStatement.new
|
||||
stmt.cores.first.projections << Nodes::SqlLiteral.new('DISTINCT id')
|
||||
stmt.cores.first.set_quantifier = Arel::Nodes::Distinct.new
|
||||
stmt.cores.first.projections << Nodes::SqlLiteral.new('id')
|
||||
stmt.limit = Arel::Nodes::Limit.new(10)
|
||||
sql = @visitor.accept stmt
|
||||
sql.must_be_like %{
|
||||
|
|
Loading…
Reference in a new issue