1

我已将一个 intarray 列添加到我的表中,并成功地将数据添加到该列中。

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

当我尝试这样的查询时:

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

我收到此错误:

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.

我通过 Homebrew for OS X 安装了 9.3,我相信它包含该intarray模块,就像我说的那样,我添加了数组列和数据没问题。还有这个:

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

更新:

我想知道在操作员工作之前是否需要一个特定的索引。在文档的示例中,他们添加了如下索引:

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

但是当我运行时,我得到:

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

我是否缺少扩展名或查询有问题或什么?

4

1 回答 1

3

好吧,我在这里找到了@>所有工作的运算符:
http ://www.postgresql.org/docs/9.3/static/functions-array.html

只是这里没有的其他内容:
http ://www.postgresql.org/docs/9.3/static/intarray.html

这向我建议了解决方案:

CREATE EXTENSION intarray;

对我的数据库运行这个让所有的操作员都在工作......我假设自从 Postgres 安装了intarray支持它就准备好了。但是必须为数据库手动启用它。

我想这对于 Postgres 开发人员来说太明显了,他们忘了把它放在文档中。

于 2014-02-03T19:06:35.203 回答