Posted on Jul 1
Today I needed to group records by a substring contents of one of the columns. We have data like task_type: "Facade (S4)", so this should be grouped as belonging to group 4 (from S4).
Turns out there’s a simple and powerful way to do this with regex-powered substring detection:
# SUBSTRING(string FROM pattern)
records.group(Arel.sql("SUBSTRING(task_type from 'S([0-9]+)$')"))
Enter fullscreen mode Exit fullscreen mode
See docs.
Top comments (0)
Subscribe
Templates let you quickly answer FAQs or store snippets for re-use.
Code of Conduct • Report abuse
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment’s permalink.
Hide child comments as well
For further actions, you may consider blocking this person and/or reporting abuse
답글 남기기