arrays - Postgres运算符不存在:

标签 arrays ruby-on-rails ruby postgresql

这是我的代码:

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

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

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新手,有人可以指出解决方案吗?

最佳答案

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

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

关于arrays - Postgres运算符不存在:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47401159/

相关文章:

javascript - 尽管对象在数组中,indexOf 仍返回 -1 - Google 电子表格脚本中的 Javascript

ruby-on-rails - ruby rails : no such file to load -- openssl on RedHat Linux Enterprise

ruby-on-rails - 未捕获的抛出 :warden in Devise Testing

ruby-on-rails - simple_form grouped select association 给出 "undefined method ` map'"

ruby-on-rails - 按出生日期计算年龄并放入年龄组

python - 云管理或基础设施管理中的自动化语言

arrays - Perl:将数据从哈希转储到 Excel 中

arrays - 在二叉最大堆中插入一个新元素

php - 数组合并具有相同索引的php

css - sass缓存破坏