Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

In my Rails 4 app I have a goal to see all contacts, where field visible_to in contacts table equal to 1. My visible_to is :integer, array: true.

However, I get the following exception:

PG::UndefinedFunction: ERROR:  operator does not exist: integer[] = integer
LINE 1: ....* FROM "contacts"  WHERE "contacts"."visible_to" IN (1)  OR...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.:
SELECT "contacts".* FROM "contacts"  WHERE "contacts"."visible_to" IN (1)  ORDER BY created_at DESC

I searched for answers and as far as I see there is an issue with a type of visible_to. However, I couldn't find the solution. I also tried to get benefit from casts hint, but in vain.

My migration:

class AddVisibleToToContacts < ActiveRecord::Migration
    def change
      add_column :contacts, :visible_to, :integer, array: true, default: [], using: 'gin'     
    end 
end

Relevant variable from Controller:

@contacts_all_user_sorted = Contact.all.where(visible_to: [1]).order("created_at DESC")
share|improve this question
1  
It should not be an array if you want to store a single value. Change to array: false. –  dezso Aug 11 '14 at 14:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.