Home > database >  Why it works different with ~~ any()?
Why it works different with ~~ any()?

Time:09-24

Let me first show you my table:

INSERT INTO my_table(name, brand, source)
VALUES ('Abc', 'Abc', 'Orig'), 
('Auchan', 'Auchan', 'Orig'), 
('Auchan', 'Auchan', 'Added'),
('dj-auchan-djd', 'Auchan', 'Added'),
('Auchan', 'Other', 'Added'),
('Other', 'oj_auchan', 'Added'),
('Other', 'Other', 'Added');

What I want to do is to delete data where source is 'Added' and brand or name is like brand where source is 'Orig'. For example here we will delete next rows:

('Auchan', 'Auchan', 'Added'), - simply name and brand is 'Auchan'
('dj-auchan-djd', 'Auchan', 'Added'), - brand ad name has 'Auchan'(but name lowercase)
('Auchan', 'Other', 'Added'), - name is 'Auchan'
('Other', 'oj_auchan', 'Added') - brand has 'Auchan' but lowercase.

So what it would be when we manually create this brands comparing:

delete
    from my_table
    where lower(name) ~~ any
           ('{%auchan%,           
  • Related