选择text - string_to_array中的x值



我有一个列在table1包含以逗号分隔的名称,如a、b、c

<表类> 名称 结果 tbody><<tr>a, d, ea, c, e, fc, d, f, g td

如果您想要的结果是布尔值,则使用exists(...):

update table1 as t1
set result = exists(
select name 
from table2 
where origin = 'UK'
and name = any(string_to_array(t1.names, ','))
);

在db<>fiddle中测试。

如果您想获得名称,使用string_agg():

update table1 as t1
set result = (
select string_agg(name, ',') 
from table2 
where origin = 'UK'
and name = any(string_to_array(t1.names, ','))
);

,Db&lt的在小提琴。

最新更新