union is not part of ActiveRecord, which might be the reason why update_all is not able to work with it.
There's a lot of magic in it :D
PostgreSQL itself is able to update rows from unions if you project the same exact row types from both queries:
PracticalDeveloper_development> select count(*) from comments;
+---------+
| count |
|---------|
| 30 |
+---------+
PracticalDeveloper_development> update comments set updated_at = now() where id in(select id from comments where id < 10 union select id from comments where id> 15);
UPDATE 24
You probably hit a limitation of ActiveRecord :-)
union
is not part of ActiveRecord, which might be the reason whyupdate_all
is not able to work with it.There's a lot of magic in it :D
PostgreSQL itself is able to update rows from unions if you project the same exact row types from both queries:
In conclusion: I don't know what's going on 🧐
Haha yeah the magic is certainly mystifying me. Guess I'll put on my wizard robes and dive into the code.
Let us know if you find anything :D