Thursday , November 14 2024

PostgreSQL – Split The String With Regex Split

In PostgreSQL we have 2 functions to split a string according to a certain character;

regexp_split_to_array and regexp_split_to_table.

regexp_split_to_array : It splits the string according to regular expression and returns its parts in an array.

regexp_split_to_table :  It splits the string into pieces according to the regular expression and returns its parts in the rows of a table.

Examples:

Split by space (' ') character and get an array:

Split by space (' ') character and get an array. Then list the first and second fields in this list separately:

Split by dot (.) character and get second part:

Split by space character and get it as a table:

Split by comma (,) and get it as a table that sorted by numbers:

Loading

About Şahap Aşçı

Leave a Reply

Your email address will not be published. Required fields are marked *