alexreisner/geocoder — Issue #136: (Heroku) #near method errors after schema update
Author: afiore
Created: 2011-10-25 22:08:29+00:00
State: open

Hi there,
I have just updated with a new column ('subscribe_newsletter') my user model (which uses geocoder). Suddenly the #near method has stopped working and throws the following error:

User.near([51.499900, -0.110502])

ActiveRecord::StatementInvalid: PGError: ERROR: column "users.subscribe_newsletter" must appear in the GROUP BY clause or be used in an aggregate function :
SELECT *, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((51.4999 - lat) * PI() / 180 / 2), 2) + COS(51.4999 * PI() / 180) * COS(lat * PI() / 180) * POWER(SIN((-0.110502 - lng) * PI() / 180 / 2), 2) )) AS distance, CAST(DEGREES(ATAN2( RADIANS(lng - -0.110502), RADIANS(lat - 51.4999))) + 360 AS decimal) % 360 AS bearing FROM "users" WHERE (lat BETWEEN 51.2104364337783 AND 51.7893635662217 AND lng BETWEEN -0.575491759360445 AND 0.354487759360445) GROUP BY users.id,users.email,users.encrypted_password,users.reset_password_token,users.reset_password_sent_at,users.remember_created_at,users.sign_in_count,users.current_sign_in_at,users.last_sign_in_at,users.current_sign_in_ip,users.last_sign_in_ip,users.authentication_token,users.name,users.username,users.is_venue,users.is_admin,users.location,users.country,users.tel,users.website,users.opentimes,users.bio

I noticed this problem only after deploying to Heroku (bamboo-ree-1.8.7 stack); The query works just fine instead on my machine, where I am running Postgres 9.1.