How to Use SPLIT_PART in Redshift
Last updated July 25, 2026 · By the SaturnSQL team
SPLIT_PART(string, delimiter, position) splits a string on a delimiter and returns the Nth piece (1-based). It returns an empty string, not NULL, when the position is past the last piece.
Position is 1-based, so position 1 is the text before the first delimiter. The delimiter is a literal string rather than a regex and can be more than one character. If the delimiter does not appear at all, position 1 returns the whole input unchanged.
SELECT SPLIT_PART('[email protected]', '@', 2) AS domain; -- example.comParse a URL path from events
Counting positions on a full URL is easy to get wrong. Splitting https://example.com/blog/post on / gives https: at 1, an empty string at 2, the host at 3, and the first path segment at 4, which is what this query groups by. Positions past the end return an empty string rather than NULL, so those rows collapse into one empty group; wrap in NULLIF(..., '') if you would rather they were NULL.
SELECT SPLIT_PART(page_url, '/', 4) AS section,
COUNT(*) AS views
FROM events
GROUP BY 1
ORDER BY views DESC;Run this in SaturnSQL
SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.
Try it free