w3resource

PostgreSQL STRING_TO_ARRAY() function

STRING_TO_ARRAY() function

The STRING_TO_ARRAY() function in PostgreSQL splits a string into an array using a specified delimiter. An optional parameter allows you to specify a string that should be treated as null during the splitting process.

Uses of the PostgreSQL STRING_TO_ARRAY() Function
  • Split Strings: Convert a delimited string into an array of elements.

  • Handle Null Values: Specify strings to be treated as nulls within the resulting array.

  • Data Parsing: Parse and structure delimited string data into an array format.

  • Dynamic Data Processing: Facilitate the manipulation and analysis of string data by converting it to an array.

Syntax:

string_to_array(text, text [, text])

Return Type:

text[]

PostgreSQL Version: 9.3

Example: PostgreSQL STRING_TO_ARRAY() function

Code:

SELECT string_to_array('xx~^~yy~^~zz', '~^~', 'yy');

Sample Output:

 string_to_array
-----------------
 {xx,NULL,zz}
(1 row)

Previous: ARRAY_UPPER function
Next: UNNEST function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/PostgreSQL/postgresql_string_to_array-function.php