In this post, I am providing a solution to split a string by using a different type of delimiters in PostgreSQL.
Splitting a string is a very common requirement for all PostgreSQL Database Developers.
I used regexp_split_to_array to split the string and store the result into a string array. You can pass any delimiters.
Below are two sample example using regexp_split_to_array():
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | SELECT a[1] AS DiskInfo ,a[2] AS DiskNumber ,a[3] AS MessageKeyword FROM ( SELECT regexp_split_to_array('Postgres Disk information : disk 2 : failed', ':') ) AS dt(a) SELECT a[1] AS DiskInfo ,a[2] AS DiskNumber ,a[3] AS MessageKeyword FROM ( SELECT regexp_split_to_array('Postgres Disk information , disk 2 , failed', ',') ) AS dt(a) |
The result:
No comments:
Post a Comment
It’s all about friendly conversation here at small review :) I’d love to be hear your thoughts!
Be sure to check back again because I do make every effort to reply to your comments here.