rails / arel

A Relational Algebra
2.06k stars 390 forks source link

unnecessary parens when combining multiple "UNION ALL" (mysql) #404

Closed bughit closed 6 years ago

bughit commented 8 years ago

https://github.com/brianhempel/active_record_union/pull/4#issuecomment-163079230

to repro:

use gem 'active_record_union', github: 'odedniv/active_record_union' in a rails (with mysql) project then with any model run the following:

User.where(id: 1).union(User.where(id: 2), User.where(id: 3)).to_sql
SELECT `users`.* FROM ( (SELECT `users`.* FROM `users` WHERE `users`.`id` = 1) UNION (SELECT `users`.* FROM `users` WHERE `users`.`id` = 2) UNION (SELECT `users`.* FROM `users` WHERE `users`.`id` = 3) ) `users`
User.where(id: 1).union_all(User.where(id: 2), User.where(id: 3)).to_sql
SELECT `users`.* FROM ( ( (SELECT `users`.* FROM `users` WHERE `users`.`id` = 1) UNION ALL (SELECT `users`.* FROM `users` WHERE `users`.`id` = 2) ) UNION ALL (SELECT `users`.* FROM `users` WHERE `users`.`id` = 3) ) `users`

note the extra grouping with UNION ALL

kbrock commented 6 years ago

Please let me know if #510 meets your needs (and if it works for you)

matthewd commented 6 years ago

Per #523, Arel development is moving to rails/rails.

If this issue is still relevant, please consider reopening it over there. (Note that the Rails repository does not accept feature request issues, and requires reproduction steps that rely on Active Record's documented API.)

kbrock commented 5 years ago

Merged into Rails