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?

Andrey Deineko
  • 49,444
  • 10
  • 105
  • 134
Matthias
  • 1,763
  • 2
  • 15
  • 30

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,089
  • 9
  • 13