RoR 4.0.3 / Postgres 9.1.12
当我在PgAdmin
SELECT extract('epoch' from expires_at) - extract('epoch' from now()) as secs_left
FROM "auctions" ORDER BY "auctions"."id" ASC LIMIT 1
我得到expires_at
(其类型为DATETIME
)与当前时间(expires_at > now()
为正数,否则为负数)的秒数正确值。
但是当我从rails执行查询时,我总是得到比正确值大得多的正值
@auction = Auction.select("extract('epoch' from expires_at) - extract('epoch' from now()) as secs_left").first
logger.debug @auction.secs_left
在控制台中我看到了
Auction Load (0.7ms) SELECT *, extract('epoch' from expires_at) - extract('epoch' from now()) as secs_left FROM "auctions" ORDER BY "auctions"."id" ASC LIMIT 1
5472.91183400154
是什么原因?