split_part(text, text, integer) — Split a string on a delimiter

Last updated: 2026-11-04

split_part(text, text, integer) — Split a string on a delimiter

split_part() cuts a string on a delimiter and returns the nth field. It is the most direct way to parse CSV rows, file paths or composite keys without first converting the row into an array; note that n is 1-based and an out-of-range index returns an empty string rather than raising an error.

Kindfunction
Example LanguageSQL

📝 Syntax

split_part(string text, delimiter text, n integer) → text

⚙️ Parameters

string textThe string to split. Type text.
delimiter textThe delimiter; it may consist of several characters. Type text.
n integerWhich field to return, counted from 1; must be greater than 0. Type integer.

Returns:text — the nth field; an empty string when n is beyond the number of fields.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

 id | order_date | product    | qty | amount
----+------------+------------+-----+--------
  1 | 2024-08-15 | USB-C Hub  |   2 | 129.90
  2 | 2024-08-16 | HDMI Cable |   1 |  39.50
(2 rows)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QWhat if a CSV field itself contains a comma?
Asplit_part() has no notion of quoting. For such data import with COPY ... WITH CSV HEADER, or use regexp_split_to_table() with a stricter pattern.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏