Arel: Add support for FILTER clause (SQL:2003)#40491
Arel: Add support for FILTER clause (SQL:2003)#40491rafaelfranca merged 1 commit intorails:mainfrom Envek:arel/filter-support
Conversation
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
|
Oh bot, just look at these reactions under first comment! How you even could think about closing this pull request? Heartless piece of code! |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Currently supported by PostgreSQL 9.4+ and SQLite 3.30+ See: - http://modern-sql.com/feature/filter - https://www.postgresql.org/docs/9.4/static/sql-expressions.html#SYNTAX-AGGREGATES - https://sqlite.org/lang_aggfunc.html#aggfilter Example: Model.all.pluck( Arel.star.count.as('records_total').to_sql, Arel.star.count.filter(Model.arel_table[:some_column].not_eq(nil)).as('records_filtered').to_sql, )
|
@sunny thanks for catching this weird naming of test examples (most probably I copied them from some project, but it was long time ago). Applied your suggestions and rebased on top of fresh |
simi
left a comment
There was a problem hiding this comment.
I really like this extension of Arel. As a followup we can open another case to expose it via ActiveRecord public API. Also it is not supported by MySQL, but it can be implemented using CASE (https://modern-sql.com/feature/filter#conforming-alternatives). It could be added to MySQL adapter later as well if needed.
|
I'd love to see this merged! |
Reopened from rails/arel#518 due to the numerous requests of users (also in rails/arel#460).
Allows to write following Ruby code:
to get following SQL:
Database support:
See: