在Postgres中等效于strftime

编程入门 行业动态 更新时间:2024-10-25 21:14:59
本文介绍了在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

本文发布于:2023-10-20 09:01:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1510525.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Postgres   strftime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!