Handling ActiveRecord `pluck` with complex SQL functions in Rails 7
I'm optimizing some code but I'm having trouble using `pluck` with a complex SQL function in my Rails 7 application... I'm trying to retrieve a list of user email domains from a `users` table, but I want to apply a custom SQL function to extract the domain from the email address. My current attempt looks something like this: ```ruby User.pluck("SUBSTRING_INDEX(email, '@', -1) as domain").uniq ``` However, when I run this, I get an behavior saying `ActiveRecord::StatementInvalid: SQLite3::SQLException: near "as": syntax behavior`. I’ve tried various ways to write the SQL function, including removing the alias and using a different SQL dialect, but I keep working with the same scenario. I also considered using `select` instead of `pluck`, but that seems to return an array of `User` objects instead of the desired domains. I’ve confirmed that my database is SQLite3, and I’m on Rails 7.0.4. I want to keep the performance high since the `users` table can have thousands of entries. Does anyone know how to correctly use `pluck` with a SQL function in this context? Any suggestions would be greatly appreciated!