I have following column in a postgres table.
col1 start end
p.[A138T;S160G;D221_E222delinsGK] 138 138
p.[A138T;S160G;D221_E222delinsGK] 160 160
p.[A138T;S160G;D221_E222delinsGK] 221 222
I am looking for a way to split the ; separated values in multiple rows. The expected output is:
col1 start end
p.A138T 138 138
p.S160G 160 160
p.D221_E222delinsGK 221 222
I am using following query but it does not works for the third row.
select
case
when start = "end" and col1 like 'p.[%' then 'p.'||(regexp_match(col1, '([A-Z]'||start||'[A-Z])'))[1]
when start != "end" and col1 like 'p.[%' then 'p.'||(regexp_match(col1, '[A-Z\d+_delins]+'||start||'[A-Z\d+_delins]+'))[1]
else col1,
start,
end
from table
Any help is highly appreciated!