Fetching latest headlines…
TIL: Postgresql's SUBSTRING function
NORTH AMERICA
🇺🇸 United StatesJuly 1, 2026

TIL: Postgresql's SUBSTRING function

0 views0 likes0 comments
Originally published byDev.to

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]+)$')"))

See docs.

Comments (0)

Sign in to join the discussion

Be the first to comment!