Search code examples
ruby-on-railspostgresqlherokurakepg

Intermittent PostgreSQL error: missing FROM-clause


I have a Rails app running on Heroku which intermittently throws Postgres 'missing FROM-clause' errors from UPDATEs executed by a Rake task.

An example UPDATE statement is:

UPDATE "temp_stats_values" 
    SET "number" = 66, 
        "average" = 0, 
        "percentage" = 0, 
        "num_out_of" = 0, 
        "updated_at" = '2013-01-12 11:43:40.067530' 
WHERE "temp_stats_values"."id" = 1330

And the error thrown is:

ActiveRecord::StatementInvalid: PG::Error: ERROR: missing FROM-clause entry for table "temp_stats_values"

The thing is, I don't know why it's expecting a FROM clause for this SQL when there clearly isn't another table involved. Also, the fact that it seems to be intermittent is pretty confusing. The errors, when they happen, are being caught by Airbrake.

Anyway, if anyone has any good ideas I'd be very grateful.


UPDATE

Example SQL Fiddle which works as expected


Solution

  • So, without any intervention these errors magically dried up, just like they magically started happening in the first place. Spooky. Anyway, thanks to all who commented.