SPLIT_PARTB

Splits string on the delimiter and returns the location of the beginning of the given field (counting from one). The VARCHAR arguments are treated as octets rather than UTF-8 characters.

Behavior Type

Immutable

Syntax

SPLIT_PARTB ( string , delimiter , field )

Parameters

string

(VARCHAR) Is the argument string.

delimiter

(VARCHAR) Is the given delimiter.

field

(INTEGER) is the number of the part to return.

Notes

Use this function with the character form of the subfield.

Examples

The specified integer of 3 returns the third string, or soupçon.

=> SELECT SPLIT_PARTB('straße~@~café~@~soupçon', '~@~', 3);
 SPLIT_PARTB
-------------
 soupçon
(1 row)

The tildes are for readability only. Omitting them returns the same results:

=> SELECT SPLIT_PARTB('straße @ café @ soupçon', '@', 3);
 SPLIT_PARTB
-------------
  soupçon
(1 row)

See what happens if you specify an integer that exceeds the number of strings: No results.

=> SELECT SPLIT_PARTB('straße @ café @ soupçon', '@', 4);
 SPLIT_PARTB
-------------
(1 row)

The above result is not null, it is an empty string.

=> SELECT SPLIT_PARTB('straße @ café @ soupçon', '@', 4) IS NULL;
 ?column?
----------
 f
(1 row)