2

これは私の開発環境では機能しますが、Postgres を使用して Heroku 経由で実行しようとすると、このエラーが発生します。

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)):

以下は、私のコントローラーからのコード行です。

Datapoint.average(:value, :conditions => ['habit_id == ?', self.habit_id])

私はレールにかなり慣れていないので、これは非常に単純な間違いである可能性があります.ここで私が間違っていることについて何か考えはありますか?

4

1 に答える 1

5

単一の等号を使用してください。

Postgresql (および SQL 標準) は、比較に単一の等号 (=) を使用します: http://www.postgresql.org/docs/8.0/static/functions-comparison.html

プログラミング言語とは異なり、SQL は update 句を除いて代入での使用をサポートする必要はありません。そのため、ほとんどのプログラミング言語で必要とされる比較用の二重等号演算子 (==) は必要ありません。

于 2012-04-07T23:02:06.423 に答える