Reputation: 87
This works in my dev environment, but when I try to run via Heroku with Postgres I get this error.
2012-04-07T21:35:14+00:00 app[web.1]: ActiveRecord::StatementInvalid
(PG::Error: ERROR: operator does not exist: integer == integer
2012-04-07T21:35:14+00:00 app[web.1]: LINE 1: ...."value") AS avg_id FROM "datapoints"
WHERE (habit_id == 1)
2012-04-07T21:35:14+00:00 app[web.1]: HINT: No operator matches the given name and argument type(s).
You might need to add explicit type casts.
2012-04-07T21:35:14+00:00 app[web.1]: : SELECT AVG("datapoints"."value") AS avg_id FROM "datapoints
WHERE (habit_id == 1)):
Below is the line of code from my controller:
Datapoint.average(:value, :conditions => ['habit_id == ?', self.habit_id])
I'm fairly new to rails so this could easily be a very simple mistake - any thoughts on what I'm doing wrong here?
Upvotes: 2
Views: 3632
Reputation: 6120
Just use a single equals sign.
Postgresql (and the SQL standard) uses a single equals sign (=) for comparison: http://www.postgresql.org/docs/8.0/static/functions-comparison.html
Unlike a programming language, SQL doesn't need to support using it for assignment except in update clauses. So, it doesn't require the double-equals operator (==) for comparison that most programming languages require.
Upvotes: 5