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?
Check Value in Array Using UbiqUbiq Reporting tool supports all the above SQL queries and makes it easy to visualize SQL results in different ways.
You need to use the ARRAY_AGG function to create an array that is the intermediate result of a SELECT statement, and then retrieve the contents of that array into an SQL array variable or parameter. For example: -- INTB IS AN OUT PARAMETER OF ORDINARY ARRAY TYPE INTARRAY. -- COL2 IS AN INTEGER COLUMN.
Try
SELECT * FROM table WHERE arr @> ARRAY['s']::varchar[]
Note that this may also work:
SELECT * FROM table WHERE s=ANY(array)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With