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

10-08 04:26