We have an easy syntax that allows us to look into an array for a single scalar,
SELECT 'foo' = ANY(ARRAY['foo', 'bar', 'baz']);
We can use the same method to match with LIKE
SELECT 'foobar' LIKE ANY(ARRAY['foo%', 'bar%', 'baz%'];
My question is what if you want to do it the other.
SELECT ANY(ARRAY['foobar', 'barbar', 'bazbar']) LIKE 'foo%'
ERROR: syntax error at or near "ANY"
LINE 1: SELECT ANY(ARRAY['foobar', 'barbar', 'bazbar']) LIKE 'foo%';
I know that syntax doesn't work, but I have expected this to work.
# SELECT ARRAY['foobar', 'barbar', 'bazbar'] LIKE 'foo%';
ERROR: operator does not exist: text[] ~~ unknown
LINE 1: SELECT ARRAY['foobar', 'barbar', 'bazbar'] LIKE 'foo%';
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
I want to filter an array to see if an element exists. Is this possible without using unnest
?
SELECT IN ('foo', 'bar')
IN ()
is just a minor wrapper around= ANY( ARRAY[] )
,SELECT 'foo' IN ('foo', 'bar');
vsSELECT 'foo' IN ('baz', 'bar');