【发布时间】:2022-08-04 15:16:28
【问题描述】:
我在 postgres 表中有以下列。
col1 start end
p.[A138T;S160G;D221_E222delinsGK] 138 138
p.[A138T;S160G;D221_E222delinsGK] 160 160
p.[A138T;S160G;D221_E222delinsGK] 221 222
我正在寻找一种方法来拆分 ;在多行中分隔值。预期的输出是:
col1 start end
p.A138T 138 138
p.S160G 160 160
p.D221_E222delinsGK 221 222
我正在使用以下查询,但它不适用于第三行。
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
非常感谢任何帮助!
标签: postgresql substring