regexp_replace 解决方案,用于从句子中剥离第一个单词或字符,如果它的唯一字符很长

a regexp_replace solution tfor stripping the first word or character from a sentence if its only character long

之前

with t1 as 
(
select           1 id,"1 university of washington,           seattle, washington" location
union all select 2 id,"a university of washington, seattle  , washington"
union all select 3 id,"b university of washington,      , washington"
union all select 4 id,"university of washington, seattle , washington"
union all select 5 id,"d university of new york,ny  , usa"
union all select 6 id,"university of new york,new york  , usa"

)
select * from t1
order by 1      

想要

with t2 as 
(
select           1 id,"university of washington,           seattle, washington" location
union all select 2 id,"university of washington, seattle  , washington"
union all select 3 id,"university of washington,      , washington"
union all select 4 id,"university of washington, seattle , washington"
union all select 5 id,"university of new york,ny  , usa"
union all select 6 id,"university of new york,new york  , usa"

)
select * from t2
order by 1 

我可以通过使用 split (location ' ') 拆分位置字符串并删除长度小于 1 个字符且偏移量为 0 的单词然后使用 string_agg 将字符串放回原处来实现此目的。

不过我确信有一个更简单的 regexp_replace 解决方案。

下面使用

select id, regexp_replace(location, r'^\w ','') location
from t1
order by 1     

有输出