我在PostgreSQL中有一个表,其值如下。
col1
; substrate
positive allosteric modulator
inducer; substrate我希望将行值拆分为“;”多列。根据我的理解,split_part()函数只适用于固定数量的值。
怎样才能得到下面的输出?
col1 col2 col3
; substrate substrate
positive allosteric modulator positive allosteric modulator
inducer; substrate inducer substrate谢谢
发布于 2022-01-19 21:59:37
您可以将其拆分为一个数组,然后访问每个数组元素:
select col1,
elements[1] as col2,
elements[2] as col3
from (
select col1, regexp_split_to_array(col1, '\s*;\s*') as elements
from the_table
) t https://stackoverflow.com/questions/70777938
复制相似问题