且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何对包含用逗号分隔值的字符串的列值执行搜索查询?

更新时间:2022-12-10 07:38:30

您可以执行以下操作。

select name from zone_table where 
string_to_array(replace(tags,' ',''),',')@>
string_to_array(replace('down, 110.22.100.3',' ',''),',');

1)删除现有字符串中的空格以进行适当的string_to_array分隔,而在前面没有任何空格,请使用replace

1) delete spaces in the existing string for proper string_to_array separation without any spaces in the front using replace

2) string_to_array 将您的字符串转换为以逗号分隔的数组。

2)string_to_array converts your string to array separated by comma.

3) @> 包含运算符

(OR)

如果要整体匹配

select name from zone_table where POSITION('down, 110.22.100.3' in tags)!=0

对于单独的比赛,您可以

For separate matches you can do

select name from zone_table where POSITION('down' in tags)!=0 and 
POSITION('110.22.100.3' in tags)!=0

关于位置的更多信息此处