How to make a select with array contains value clause in psql

拜拜、爱过 提交于 2019-11-26 12:01:54

问题


I have column arr which is of type array.

I need to get rows, where arr column contains value s

This query:

SELECT * FROM table WHERE arr @> ARRAY[\'s\']

gives the error:

ERROR: operator does not exist: character varying[] @> text[]

Why does it not work?

p.s. I know about any() operator, but why doesn\'t @> work?


回答1:


Try

SELECT * FROM table WHERE arr @> ARRAY['s']::varchar[]



回答2:


Note that this may also work:

SELECT * FROM table WHERE s=ANY(array)



回答3:


SELECT * FROM table WHERE arr && '{s}'::text[];

Compare two arrays for containment.



来源:https://stackoverflow.com/questions/16606357/how-to-make-a-select-with-array-contains-value-clause-in-psql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!