limit/first broken on Oracle when using GROUP BY #128

Closed
cdinger opened this Issue Jul 14, 2012 · 0 comments

Comments

Projects
None yet
1 participant

cdinger commented Jul 14, 2012

When you build a query with a GROUP BY in Oracle, any use of .first() or .limit() doesn't produce a subquery like it should. There's a comment in Visitors::Oracle about this, but there's no check in the code.

For example an arel query like this:

things = Thing.arel_table
Thing.group(things[:id]).having(things[:thing_type].count.gt(2)).select(things[:id]).first

Generates SQL like this (which returns no rows):

select id
from things
where rownum <= 1
group by id
having count(thing_type) > 2

It should wrap everything in a subquery for limiting the results:

select * from (
  select id
  from things
  group by id
  having count(thing_type) > 2
) where rownum <= 1

I'm not super familiar with the internals of arel, but I'll try to demonstrate this in a test case and submit a fix.

matthewd closed this in #315 Sep 16, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment