Matthias
Matthias

Reputation: 1953

Rails: Using distinct with where

I have an ActiveRecord query:

Shareholder.where(is_company: false).distinct

which gives me the error:

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

The SQL query created by ActiveRecord:

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

I'm a bit puzzled that this does not work. What is wrong?

Upvotes: 2

Views: 3107

Answers (1)

Elena  Unanyan
Elena Unanyan

Reputation: 1209

Distinct does not work with json column, but you can try this

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

Upvotes: 5

Related Questions