Tried looking around online, couldn't find much on this.
Suppose the following:
create schema if not exists sb;
create table if not exists sb.test (id serial primary key);
insert into sb.test values (1), (2), (3);
select * from sb.test where id != any('{}'::int[])
Why is the resulting set empty?
If I do this, then it works as expected:
select * from sb.test where id != any('{}'::int[])
-- [ { "id": 2 }, { "id": 3 } ]
How can I get the first query to return all records?
1,2,3you inserted in your table would all be returned byselect [...] where id != any('{1, 2, 3}'::int[])since1is different from at least one element in[1,2,3], same for2and same for3; of course, they all are equal to at least one element in[1,2,3]too.allinstead ofanyyields the expected result (select * from sb.test where id != all('{}'::int[])). Is this the answer to my question, perhaps?