在 Heroku (postgres) 上将 Rails 3 应用程序插入生产环境时出现错误,而在本地 (sqlite) 代码工作正常 - 我查看了 Postgres 手册但无济于事:
我的代码:
(strftime('%s','now') - strftime('%s', posts.created_at)
错误:
LINE 1: SELECT posts.*, ((strftime('%s','now') -...
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
最佳答案
在 PostgreSQL 中没有函数 strftime。要计算日期之间的秒数,您可以使用:
SELECT extract(epoch from now() - posts.created_at);
同样重要的是要注意在 PostgreSQL 中你有区间数据类型,所以如果你只是减去 (now() - posts.created_at) 它会为你返回一个很好的区间类型,它可以很容易地用 to_char 格式化。
关于Sqlite 到 Postgres (Heroku) 日期/时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5566530/