Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
cdinger opened this Issue · 0 comments

1 participant

@cdinger

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 matthewd closed this in #315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.