这是我的代码:
.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/