2

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?

ssuperczynski
  • 3,190
  • 3
  • 44
  • 61
Matthias
  • 1,884
  • 2
  • 18
  • 35

1 Answers1

5

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

Shareholder.select("DISTINCT ON (shareholders.id) shareholders.*").where(is_company: false).distinct
Elena Unanyan
  • 1,149
  • 9
  • 14