string_to_table()

A function to splt a string at a specified delimiter returning a set of values
This entry relates to a PostgreSQL feature which is part of PostgreSQL 14, due to be released in late 2021.

string_to_table() is a function to split a string at a specified delimiter returning a set of values.

string_to_table() was added in PostgreSQL 14.

Usage

string_to_table() provides the set-based equivalent to string_to_array(), and is functionally the same albeit somewhat faster than UNNEST(string_to_array().

Note that string_to_table() is not suitable for general parsing of CSV strings, as splits are made on each occurrence of the delimiter and it does not consider whether the delimiter is embedded within a quoted string.

Change history

Examples

Basic usage of string_to_table():

postgres=# SELECT string_to_table('foo,bar,baz,',');
 string_to_table 
-----------------
 foo
 bar
 baz
(3 rows)

Not suitable for parsing CSV strings:

postgres=# SELECT string_to_table('foo,bar,baz,"baz,boo"',',');
 string_to_table 
-----------------
 foo
 bar
 baz
 "baz
 boo"
(5 rows)

Categories

System function

See also

string_to_array(), regexp_split_to_table(), regexp_split_to_array(), split_part()