当 Heroku 在我的本地 Rails 环境中运行良好时,为什么我会在 Heroku 上收到 PG 错误?

发布于 2024-09-24 02:39:29 字数 1352 浏览 1 评论 0原文

我收到以下错误:

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 

它在本地工作正常,但是当我推送到 Heroku 时,我收到错误:

我需要更改什么才能在 Heroku 上的 Postgres 上工作?

@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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

她说她爱他 2024-10-01 02:39:29

从错误消息来看:

AS postalcard_count,来自

在您的查询中删除这个逗号,这是您的错误。

From the errormessage:

AS postalcard_count, FROM

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

初吻给了烟 2024-10-01 02:39:29

看起来这是 PG 特有的,所以我完全改变了数据库结构。

It looks like this was a PG specific so I changed the database structure altogether.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文