postgresql 如何在psql中使用包含值子句的数组进行选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16606357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a select with array contains value clause in psql
提问by Oto Shavadze
I have column arr
which is of type array
.
我有arr
类型的列array
。
I need to get rows, where arr
column contains value s
我需要获取行,其中arr
列包含值s
This query:
这个查询:
SELECT * FROM table WHERE arr @> ARRAY['s']
gives the error:
给出错误:
ERROR: operator does not exist: character varying[] @> text[]
错误:运算符不存在:字符变化[] @> text[]
Why does it not work?
为什么它不起作用?
p.s. I know about any()
operator, but why doesn't @>
work?
ps 我知道any()
运营商,但为什么不@>
工作?
回答by Wojtas
Try
尝试
SELECT * FROM table WHERE arr @> ARRAY['s']::varchar[]
回答by AetherUnbound
Note that this may also work:
请注意,这也可能有效:
SELECT * FROM table WHERE s=ANY(array)
回答by vol7ron
SELECT * FROM table WHERE arr && '{s}'::text[];
Compare two arrays for containment.
比较两个数组的包含情况。