SPLIT_PART()

All functions > STRING > SPLIT_PART()

Returns a specific part of a string after splitting by a delimiter.

Signatures

Returns: The specified part after splitting, or empty string if index out of range

SPLIT_PART(string: VARCHAR, delimiter: VARCHAR, index: BIGINT) → VARCHAR
sql
ParameterTypeRequiredDescription
stringVARCHARYesString to split
delimiterVARCHARYesDelimiter to split on
indexBIGINTYes1-indexed position of the part to return

Notes

  • Index is 1-based (first part is 1, not 0)
  • Returns empty string if index is out of bounds
  • More efficient than SPLIT when only one part is needed
  • If STRING, DELIMITER, or INDEX is NULL the result is NULL (use typed NULLs; bare NULL fails inference)

Examples

FeatureQL
SELECT
    f1 := SPLIT_PART('2024-01-15', '-', 1), -- Get year from date
    f2 := SPLIT_PART('2024-01-15', '-', 2), -- Get month from date
    f3 := SPLIT_PART('2024-01-15', '-', 3), -- Get day from date
    f4 := SPLIT_PART('apple-banana-cherry', '-', 2), -- Get middle element
    f5 := SPLIT_PART('single', '-', 1), -- No delimiter found
    f6 := SPLIT_PART('2024-01-15', '-', 99), -- Out-of-range index is empty string
    f7 := SPLIT_PART(NULL(VARCHAR), '-', 1) -- NULL yields NULL
;
Result
f1 VARCHARf2 VARCHARf3 VARCHARf4 VARCHARf5 VARCHARf6 VARCHARf7 VARCHAR
20240115bananasingle(empty)NULL

Last update at: 2026/05/26 17:22:09