PostgreSQL 18 reference · String Functions
PostgreSQL SPLIT_PART() Function
Split a string on a delimiter and return the nth field (1-based). Negative n counts from the end.
PostgreSQL 18
Syntax
split_part(string, delimiter, n)
Parameters
| Parameter | Description |
|---|---|
string |
The input text. |
delimiter |
The separator text. |
n |
Which field; negative counts from the end. |
Return value
Text (empty if the field doesn't exist).
Examples
SELECT split_part('[email protected]', '@', 2) AS domain,
split_part('2026-03-09', '-', 1) AS year;
Output
domain | year -------------+------ example.com | 2026 (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT split_part('a.b.c.tar.gz', '.', -1) AS last_part;
Output
last_part ----------- gz (1 row)
Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| PostgreSQL 14 | A negative n counts fields from the end. |
Related
STRING_TO_ARRAY()· Split a string on a delimiter into a text array. A third argument turns matching fields into NULL.SUBSTRING()· Extract part of a string by 1-based position and length, or the part matching a regular expression.REGEXP_SPLIT_TO_TABLE()· Split a string on a regular expression and return one row per piece. regexp_split_to_array() returns an array.- SQL String Functions · tutorial