views:

54

answers:

1

I am getting the following error:

ReportsController#return_search (ActiveRecord::StatementInvalid) "PGError: ERROR: syntax error at or near \"FROM\"\nLINE 5: ...OUNT(contact_postalcards.id) AS postalcard_count, FROM \"cont...\n 

It works fine locally, but when I push to heroku I get the error:

What do I need to change so it will work also on Postgres on Heroku?

@list = Contact.find :all,
  :select => "companies.name AS co_name, 
             companies.id AS comp_id, 
              COUNT(contact_emails.id) AS email_count, 
              COUNT(contact_calls.id) AS call_count, 
              COUNT(contact_letters.id) AS letter_count, 
              COUNT(contact_postalcards.id) AS postalcard_count",

  :conditions => ['contact_emails.date_sent < ? and contact_emails.date_sent > ?', 
                  report_end_date, report_start_date],

  :joins => [
    "LEFT JOIN companies ON companies.id = contacts.company_id",
    "LEFT JOIN contact_emails ON contact_emails.contact_id = contacts.id",
    "LEFT JOIN contact_letters ON contact_letters.contact_id = contacts.id",
    "LEFT JOIN contact_postalcards ON contact_postalcards.contact_id = contacts.id",
    "LEFT JOIN contact_calls ON contact_calls.contact_id = contacts.id"
  ],
  #:group => "companies.id"
   :group => "companies.name"
puts @list[0].attributes.inspect
+1  A: 

From the errormessage:

AS postalcard_count, FROM

Drop this comma , in your query, it's your bug.

Frank Heikens
why does this work locally?
Angela
Because the query must be different. The SQL is wrong and no brand of database will accept it. Log the SQL query on both databases and see the difference between both situations.
Frank Heikens