Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

sql - 'Not ilike any' clause with wildcard from an array doesn't work

Just as in title, following code doesn't filter anything at all, it returns all rows while without 'NOT' it works just fine. Where's the problem?

create table test (value text);

    insert into test values
    ('Test1'),
    ('foo'),
    ('bar'),
    ('foobar'),
    ('foobar2'),
    ('foobar3'),
    ('foo1bar'),
    ('foo bar'),
    ('barbar');
    
    select *
    FROM test
    WHERE value NOT like any (array['%foo%', '%foo bar%', '%xx%']) 

https://www.db-fiddle.com/f/gCFy3K97gQy7gxomAL2Qm7/0

question from:https://stackoverflow.com/questions/65891325/not-ilike-any-clause-with-wildcard-from-an-array-doesnt-work

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I assume you mean not like any is not working. And I think that is because you want not like all:

SELECT *
FROM test
WHERE value  like all (array['%foo%', '%foo bar%', '%xx%']) 

Here is a db<>fiddle.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...