i have a problem with splitting a String on a database cell, i got an old SQL version and I cannot use the SPLIT_STRING() function that would solve my problem. I found that there is another function that seems to do the same job ( regexp_split_to_array ) but i don't understand the expression i need to use for splitting the string as i want.
EG: i have a character varying string like this
040078192-1.25;038250054-1.44 // variable number of segment like "040078192-1.25;"
and I need to split it two times, the first by the semicolon ';', the second by the '-'. so what would it be the expression in
regexp_split_to_array('040078192-1.25;038250054-1.44', {exp?})
to make it work?
also if you know any other way to solve the problem compatibile with older version of sql I am all ears.
edit: i'm using pgadmin3 with plain sql. What i want to obtain is an array like {040078192-1.25, 038250054-1.44, 038143254-1.84, ... } then i want to do the same work on the array but using the '-' as divider and obtain something like: {{040078192, 1,25}, { 038250054,1.44}, ...}
If you are using Postgres or a Postgres-compatible database, then you want:
select regexp_split_to_array('040078192-1.25;038250054-1.44', '[-;]')
Here is a db<>fiddle.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.