问题
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