Postgres运算符不存在:

时间:2017-11-20 21:13:45

标签: ruby-on-rails ruby postgresql

这是我的代码:

.having('(COUNT(DISTINCT taggings.tag_id) = 0 OR array[?] <@ array_agg(taggings.tag_id))', tag_ids)

执行上述查询时出现followint错误:

ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR:  operator does not exist: text[] <@ integer[]
LINE 1: ...OUNT(DISTINCT taggings.tag_id) = 0 OR array[NULL] <@ array_a...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

我是postgresql的新手,有人可以指出解决方案吗?

1 个答案:

答案 0 :(得分:2)

您应该将数组显式地转换为int[],因为array[null]已解析为text[]

... OR array[?]::int[] <@ array_agg(taggings.tag_id)