How to make a select with array contains value cla

2019-01-08 13:18发布

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?

3条回答
再贱就再见
2楼-- · 2019-01-08 13:49

Try

SELECT * FROM table WHERE arr @> ARRAY['s']::varchar[]
查看更多
一纸荒年 Trace。
3楼-- · 2019-01-08 13:52

Note that this may also work:

SELECT * FROM table WHERE s=ANY(array)
查看更多
Lonely孤独者°
4楼-- · 2019-01-08 14:08
SELECT * FROM table WHERE arr && '{s}'::text[];

Compare two arrays for containment.

查看更多
登录 后发表回答