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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

split_part(string, delimiter, n)

Parameters

ParameterDescription
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

Pick a field
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.

From the end (14+)
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

VersionChange
PostgreSQL 14A negative n counts fields from the end.

Was this page helpful?