Can I index array columns in Postgresq 9.1 to support:
select * from t where 100 < any(a) and 100 > any(a)
Where a
is an integer array (with rows that have some values like {90,110}
, so the query isn't returning empty.)
Details
create table t ( a integer[] )
insert into t values ('{90,110}'::integer[])
Running explain analyze
on the query above yields:
Seq Scan on t (cost=0.00..1.07 rows=2 width=32) (actual time=0.009..0.009 rows=1 loops=1)
Filter: ((100 < ANY (a)) AND (100 > ANY (a)))
Total runtime: 0.023 ms
Background
The following question describes an approach but doesn't seem to work for non-fixed-length arrays:
Can PostgreSQL index array columns?
The Postgres docs describe the built-in GIN operators, but they don't appear to support greater than/less than operations:
As an example, the standard distribution of PostgreSQL includes GIN operator classes for one-dimensional arrays, which support indexed queries using these operators: <@, @>, =, &&