I have a postgres array column with a gin index:
CREATE TABLE things (
id integer NOT NULL,
tags character varying(255)[]
);
CREATE INDEX index_things_on_tags ON things USING gin (tags);
There are a few ways to check for the presence of an element in the column, using various array operators. Here are the ones I've seen:
select * from things where 'blue' = ANY (tags)
select * from things where tags <@ '{"blue"}'
select * from things where '{"blue","yellow"}' && tags;
In postgres 9.3:
- Will the first one use the gin index?
- I'm pretty sure the second one will use the index. However, it is different from the first. it doesn't allow me to check if blue is one of the tags, it requires me to specify the exact array. Is there a way to make the style of syntax in 2 achieve what 1 is achieving?
- In the third, I want any row that has any one of blue or yellow. Will this query use the gin index? If not, how can I do this query with an index?
explain analyze
and all your questions will be answered – a_horse_with_no_name Mar 1 '14 at 1:26