本文介绍了在Postgres中等效于strftime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将我的SQLite数据库迁移到开发服务器上的Postgres之后,我得到了
After migrating my SQLite database to Postgres on the development server, I get the
PG::UndefinedFunction: ERROR: function strftime(unknown, date) does not exist是否有一个我可以用来保持其功能的函数我的应用程式?
Is there a function I could use to keep the functionality across my app?
编辑:尝试使用to_char但失败了。特别是,我不明白如何在诸如
tried using to_char but failed miserably. In particular, I do not understand how to implement it in a construction such as
def self.query_by_year_month(y, m) where("strftime('%Y', date) = ? and strftime('%m', date) = ?", y, m) end谢谢!
推荐答案看起来像它是学习SQL的绝佳时机!使用以下代码使我的方法生效:
Looks like it is a great time to start learning SQL! Made my method work using the following code:
def self.query_by_year_month(y, m) where("extract(year from date) = ? and extract(month from date) = ?", y, m) end更多推荐
在Postgres中等效于strftime
发布评论