2

I have code like this:

hh = History.select("STRFTIME(\"%Y-%m-%d %H\", created_at) AS created_at, ..., count(*) AS count_all")
puts hh[0].created_at

If config.active_record.default_timezone isn't set that code works correctly, otherwise hh[0].created_at = nil.

Why?

And how I can fix it?

4

1 回答 1

0

尝试在控制台中运行它:

History.select("STRFTIME(\"%Y-%m-%d %H\", created_at) AS created_at, ..., count(*) AS count_all").to_sql

这将向您显示发送到 Sqlite3 的输出,然后您可以检查它与它期望的 SQL 项目。在您的情况下select,对 Postgres SQL 风格有效,但对 Sqlite3 无效

于 2012-12-22T05:09:08.647 回答