我有一张看起来像这样的表
id carrier
A1 | 66.87.151.2,sprint pcs,2015-05-21,2015-05-21,66.87.151.145,sprint pcs,2015-05-21,2015-05-21,66.87.150.131,sprint pcs,2015-05-13,2015-05-13
|
B1 | 67.83.18.128,optimum online,2015-05-09,2015-05-09,b8bcdb64-72c2-4578-9db5-c011263b1180 69.204.80.158,time warner cabl,
|
C1 | 76.180.4.64,time warner cable,2015-07-01,2015-07-29,66.87.137.65,sprint pcs
我想返回一个看起来像这样的表
id carrier
A1 | sprint pcs
A1 | sprint pcs
A1 | sprint pcs
B1 | optimum online
B1 | optimum online
C1 | time warner cable
C1 | sprint pcs
我唯一能想到的是应用正则表达式运算符
regex_replace(carrier,'[^ a-z]','')或类似的东西,
但我没有运气。
答案 0 :(得分:0)
将文本列转换为数组,取消它并检查正则表达式的元素:
select id, elem
from (
select id, unnest(string_to_array(carrier, ',')) elem
from the_table
) sub
where elem ~ '^[a-z ]+$';
id | elem
----+-------------------
A1 | sprint pcs
A1 | sprint pcs
A1 | sprint pcs
B1 | optimum online
B1 | time warner cabl
C1 | time warner cable
C1 | sprint pcs
(7 rows)