gpt4 book ai didi

ruby-on-rails - rails PG::InvalidDatetimeFormat:错误:时间戳类型的输入语法无效

转载 作者:行者123 更新时间:2023-11-29 13:50:14 26 4
gpt4 key购买 nike

我正在尝试显示数据库中的图片,这些图片是在同一周内上传的,并且很喜欢。这是我的做法

def trending_wide
# binding.pry
date = DateTime.now.utc
likes = Like.where('created_at >= ? and created_at <= ?', date.beginning_of_week, date.utc.end_of_week).select(:selfy_id)
time = 'created_at >= ? and created_at <= ?', date.beginning_of_week, date.utc.end_of_week
top = Selfy.where(id: likes, created_at: time)
top.order("COALESCE(likes_count, 0) DESC").limit(6)
end

我收到这个错误

PG::InvalidDatetimeFormat: ERROR:  invalid input syntax for type timestamp: "created_at >= ? and created_at <= ?"
LINE 1: ...23:59:59.999999')) AND "selfies"."created_at" IN ('created_a...
^
: SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "selfies" WHERE "selfies"."id" IN (SELECT "likes"."selfy_id" FROM "likes" WHERE (created_at >= '2017-02-20 00:00:00' and created_at <= '2017-02-26 23:59:59.999999')) AND "selfies"."created_at" IN ('created_at >= ? and created_at <= ?', '2017-02-20 00:00:00', '2017-02-26 23:59:59.999999') LIMIT $1) subquery_for_count

我做错了什么

最佳答案

根据上面给出的答案,我可以用这个解决

 def trending_wide
# binding.pry
date = DateTime.now.utc
likes = Like.where('created_at >= ? and created_at <= ?', date.beginning_of_week, date.utc.end_of_week).select(:selfy_id)
top = Selfy.where(id: likes, created_at: Time.current.all_week)
top.order("COALESCE(likes_count, 0) DESC").limit(6)
end

关于ruby-on-rails - rails PG::InvalidDatetimeFormat:错误:时间戳类型的输入语法无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42389716/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com