-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ids as a function alias #4
base: master
Are you sure you want to change the base?
Conversation
Um, do we really need it? I mean, compare with other "function aliases": I've added function aliases (and calculate_all gem itself) for cases when you going to fetch a lot of aggregates in one pass, like I actually considered it a year ago, but didn't add it because of reasons above. There're a lot of nice functions in https://www.postgresql.org/docs/9.6/static/functions-aggregate.html (I love percentiles, for example), but they are all made possible to be used by this gem already. I would consider adding postgres only |
Also, I never considered |
Well I of course don't use it with only fetching the ids. I use it in an API call which returns multiple averages and ids grouped by some attribute. So I do use it now in a combination with other aggregates. But I agree that it is not really generic and if you start on adding this alias, you should probably include more postgres aggregate functions. Maybe a good idea to leave this PR open for now and not use it until I / we have found a nice generic way of combining this stuff. On the other hand, things like By the way, did you also wonder why this is not included in |
I've thought about making a patch for active_record, as an additional form to call But I feel it doesn't really fit, at least, right now. ActiveRecord isn't really made with using raw sql fragments in mind, and aggregating stuff is so basic, even with this gem it isn't advanced much into the relation realm. Looks like anyone who needs something more complex than CRUD has to juggle with arrays of hashes of arrays returned by a private activerecord API, or jump straight to That gem in particular was extracted from code in which I tried to use more advanced stuff, see http://stackoverflow.com/questions/35210823/why-could-postgresql-9-5s-cube-rollup-and-grouping-sets-be-slower-than-equival/35544953 I just noticed that first particular step could be implemented with public API It's not included or written by someone else because not a lot of people need it, I think. Do you know any alternatives for this gem? And you are probably the only active user of this one. |
Hi there, I found myself fetching the associated ids during a call during my project multiple times. I performed this by calling
I've now added the
:ids
as a function alias but theARRAY_AGG
function only works on Postgres.On MySQL sort of similar behaviour can be achieved by using the group-concat function but it returns a string instead of an array. This can later be parsed but I did not put too much effort in this since I don't use MySQL. In addition you would need a check in the helpers module to see what database service you are using. Maybe someone has an idea and we can have a discussion about this.