$ Customer.send("today").count
SELECT COUNT(*) FROM "customers" WHERE (`customers`.created_at >
'2014-02-07 05:00:00.000000')
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error
at or near "."
LINE 1: ...LECT COUNT(*) FROM "customers" WHERE (`customers`.created_at > '2014-02-07 05:00:00.000000')
当我将 MYSQL 数据库转换为 PG 时,我收到此错误,如何解决此问题。如果我在 MySQL 中纠正这个查询,那么它工作正常,但在 PG 中出现错误。
请帮助我...!
提前致谢
最佳答案
用于引用的反引号是一种 MySQL 主义,标准 SQL 和 PostgreSQL 使用双引号来引用标识符。你在某个地方:
where('`customers`.created_at > ?', something)
但 PostgreSQL 希望看到:
where('"customers".created_at > ?', something)
但是,由于表名是小写且不是保留字,因此您可以删除引号并获得更易于阅读且可在两个数据库中使用的内容:
where('customers.created_at > ?', something)
大概需要在 send
范围内进行此更改。
关于mysql - 将 mysql 查询转换为 postgresql 后出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21634543/