Regex 基于分隔符拆分列值并与postgres中的另一列匹配

Regex 基于分隔符拆分列值并与postgres中的另一列匹配,regex,postgresql,split,Regex,Postgresql,Split,我在postgres模式的表中有以下列 ID feature start end EBI-15947845 p.C29S 29 29 EBI-15983374 p.E283C 283 283 EBI-16057637 p.[L44D;A47D;I66D;L67D] 66

我在postgres模式的表中有以下列

ID              feature                    start         end
EBI-15947845    p.C29S                     29            29
EBI-15983374    p.E283C                    283           283
EBI-16057637    p.[L44D;A47D;I66D;L67D]    66            66
EBI-16057637    p.[L44D;A47D;I66D;L67D]    47            47
EBI-16057637    p.[L44D;A47D;I66D;L67D]    44            44
EBI-16057637    p.[L44D;A47D;I66D;L67D]    67            67
EBI-2266598     p.D1305_D1306delinsKK      1305          1306
我想转换“feature”列,使条目与“start”和“end”列的值相匹配。为了更清楚,下面是我在转换后想要的列

ID              feature     start        end
EBI-15947845    p.C29S      29           29
EBI-15983374    p.E283C     283          283
EBI-16057637    p.I66D      66           66
EBI-16057637    p.A47D      47           47
EBI-16057637    p.L44D      44           44
EBI-16057637    p.L67D      67           67
EBI-2266598     p.D1305_D1306delinsKK      1305          1306
我可以想出一种方法,但无法实施。列值应按拆分;然后使用开始/结束值对每个组件应用正则表达式匹配,并在遇到匹配时进行拾取和替换,然后用p.连接

任何建议都会很有帮助


谢谢

我认为您实际上不需要拆分这些值。据我所知,使用应该足够了:

select id, 
       case 
         when start = "end" and feature like 'p.[%' 
           then 'p.'||(regexp_match(feature, '([A-Z]'||start||'[A-Z])'))[1] 
         else feature
       end as feature,
       start,
       "end"
from the_table

我认为您实际上不需要拆分这些值。据我所知,使用应该足够了:

select id, 
       case 
         when start = "end" and feature like 'p.[%' 
           then 'p.'||(regexp_match(feature, '([A-Z]'||start||'[A-Z])'))[1] 
         else feature
       end as feature,
       start,
       "end"
from the_table

如果
start
end
的值不同怎么办?@GMB它将保持在最终表格中的状态。为了清楚起见,我在表的末尾添加了一行。如果
start
end
有不同的值怎么办?@GMB它将保持在最后一个表中的状态。为了清楚起见,我在桌子的末尾加了一行。太好了!!您能解释一下添加[1]的目的吗?@rshar:因为
regexp\u match()
返回一个数组。太好了!!您能解释一下添加[1]的目的吗?@rshar:因为
regexp\u match()
返回一个数组。