LIKE运算符,用于列的数组值 [英] LIKE operator for array value of column
本文介绍了LIKE运算符,用于列的数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有x和y列的简单表。
这些列包含用于匹配的类似SQL的模式。
x列是varchar数组(VARCHAR [])
y列是简单字符串(VARCHAR)
I have simple table with columns x and y. These columns contains SQL-like patterns for matching. Column x is array of varchar (VARCHAR[]) Column y is simple string (VARCHAR)
例如:
第一行:
x y
{'asd','sdf%','%er%'} %er%
我有此查询:
SELECT x, 'ters' LIKE ANY("x"), y, 'ters' LIKE "y" FROM s
所以此查询的结果是:
"{'asd','sdf%','%er%'}";f;"%er%";t
我的麻烦是:
为什么 Like
运算符为什么起作用
Why does the LIKE
operator work for Y but not for X.
如何匹配 VARCHAR []
?
推荐答案
您输入的数组格式错误:
You have a wrong input format for the array:
select x, 'ters' like any (x), x[3]
from (values
('{asd,sdf%,%er%}'::varchar[]),
($${'asd','sdf%','%er%'}$$)
) s(x);
x | ?column? | x
-----------------------+----------+--------
{asd,sdf%,%er%} | t | %er%
{'asd','sdf%','%er%'} | f | '%er%'
> https://www.postgresql.org/docs/current/static/arrays.html#ARRAYS-INPUT
这篇关于LIKE运算符,用于列的数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文