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

Oto Shavadze picture Oto Shavadze · May 17, 2013 · Viewed 103.1k times · Source

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?

Answer

Wojtas picture Wojtas · May 17, 2013

Try

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