I'm trying to run the following raw query in rails, only to see it fail:
query = 'SELECT * FROM users WHERE id IN ($1);'
results = ActiveRecord::Base.connection.exec_query(query, "My query", [ [1,2] ]);
What am I doing wrong?
The error I'm getting starts with this:
Could not log "sql.active_record" event. NoMethodError: undefined method `binary?' for 1:Fixnum
Clearly, I'm misusing [1, 2]
bind params somehow, but I couldn't find a proper example myself.
P.S. This is minimal failing example, derived of a much more advanced query that can't be turned into ActiveRecord chain of calls. In other words – I can't rely on Arel when building my query.
P.P.S. I'm using rails 4.0.1
and postgresql 9.3
query = 'SELECT * FROM users WHERE id IN (?);'
results = ActiveRecord::Base.connection.exec_query(query, [1,2])
– Etruria