gpt4 book ai didi

ruby-on-rails - rails : Using distinct with where

转载 作者:行者123 更新时间:2023-12-02 04:05:31 25 4
gpt4 key购买 nike

我有一个 ActiveRecord 查询:

Shareholder.where(is_company: false).distinct

这给了我错误:

ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: could not identify an equality operator for type json

ActiveRecord 创建的 SQL 查询:

SELECT DISTINCT "shareholders".*
FROM "shareholders"
WHERE "shareholders"."deleted" = $1 AND "shareholders"."is_company" = $2

我有点困惑,这不起作用。怎么了?

最佳答案

Distinct 不适用于 json 列,但您可以尝试这个

Shareholder.select("DISTINCT ON (shareholders.id) shareholders.*").where(is_company: false).distinct

关于ruby-on-rails - rails : Using distinct with where,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39767547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com