Search Postgresql Archives

jsonb and comparison operators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Is it possible to get this query (or a similar one) to use an index? 

I want to return all rows that have a value of less than 10. I have arbitrary keys I want to check (not just 'a').

drop table if exists test;                                                                          
create table test (j jsonb);                                                                        
insert into test select json_build_object('a', i)::jsonb from generate_series(1, 100000) i;         
create index on test using gin(j);                                                                                                
vacuum analyze test;                                                                                
                                                                                                    
select * from test where (j->>'a')::int < 10;

I tried
select * from test where j->'a' < 10::json::jsonb; 
but didn't seem to use the index.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux