1

I have added an intarray column to my table and successfully added data to the column.

CREATE TABLE my_table
(
  ...
  tag_ids integer[],
)

When I try a query like this:

SELECT id, tag_ids from my_table where tag_ids @@ ARRAY[1,2]

I get this error:

ERROR:  operator does not exist: integer[] @@ integer[]
LINE 1: SELECT id, tag_ids from core_tile where tag_ids @@ ARRAY[1,2...
                                                    ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

I installed 9.3 via Homebrew for OS X, which I believe includes the intarray module, and like I said I added the array column and data no problem. Also this:

SELECT * FROM pg_available_extensions
...
"intarray";"1.0";"";"functions, operators, and index support for 1-D arrays of integers"

Update:

I wondered if I needed a specific index before the operators would work. In the example in the docs they add an index like this:

CREATE INDEX my_index ON my_table USING GIST (tag_ids gist__int_ops);

But when I run that I get:

ERROR:  operator class "gist__int_ops" does not exist for access method "gist"

Am I missing an extension or is something wrong with the query or what?

1 Answer 1

3

Well, I found the operators here such as @> all work:
http://www.postgresql.org/docs/9.3/static/functions-array.html

It's just the additional ones here that didn't:
http://www.postgresql.org/docs/9.3/static/intarray.html

That suggested to me the solution:

CREATE EXTENSION intarray;

Running this against my db got all the operators working... I had assumed since Postgres was installed with intarray support it was all ready to go. But it has to be manually enabled for the db.

I guess this is so obvious for the Postgres devs they forgot to put it in the documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

There are a couple of related (possible helpful) answers suggesting to create the extension intarray for additional operators.
holy crap, thank you so much I was sitting here scratching my head why intarray stuff wouldn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.