In other words, can any complex sql statement (non-db specific SQL code) be broken up into constituent ActiveRecord statements? For the sake of the argument, I am not considering performance or multiple calls to the database (which could of course be avoided with raw SQL).
In other words, can any complex sql statement (non-db specific SQL code) be broken
Share
No. While Active Record does most abstractions fairly well, some calls are database specific and cannot be abstracted like you mentioned. Others just simply cannot be represented. Something like the SQL CASE call is an example of code I couldn’t reconstruct with Active Record. On a reasonably large dataset (~30000), looping was not possible as it took upwards of 20 seconds to run compared to the speed of SQL.
I would suggest using the docs and some judgment to make an informed decision about when to use SQL.