gpt4 book ai didi

mysql - name_scope 的 PGError 语法问题

转载 作者:行者123 更新时间:2023-11-29 15:04:30 24 4
gpt4 key购买 nike

我有以下的named_scope,它在MySQL和sqlite中工作正常,但在Postgres中却很糟糕:

course.rb

named_scope :current, :conditions => ['start < ? AND end > ? ', Time.now, Time.now], :order => 'start ASC'

然后我就打电话:

Course.current

我收到错误:

PGError: ERROR: syntax error at or near "end" LINE 1: ... WHERE (start < '2010-03-17 14:03:24.995746' AND end > '201... ^ : SELECT count(*) AS count_all FROM "courses" WHERE (start < '2010-03-17 14:03:24.995746' AND end > '2010-03-17 14:03:24.995748' )

我的 google-fu 失败了,所以我希望 Stack Overflow 不会失败。关于如何使该范围对 Postgres 友好有什么想法吗?谢谢,

德鲁

最佳答案

END是一个关键字,您必须使用其他名称或将其放在双引号“end”之间。

如果您在列名周围使用双引号,并且也对 MySQL 使用此代码,请通过设置正确的 SQL 模式告诉 MySQL 接受双引号作为对象标识符:ANSI_QUOTES

关于mysql - name_scope 的 PGError 语法问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2465917/

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