我正在尝试加载最新的10艺术,按user_id分组,并由created_at订购。这在SqlLite和MySQL上工作得很好,但在我的新PostgreSQL数据库上会出现错误。
Art.all(:order => "created_at desc", :limit => 10, :group => "user_id")
ActiveRecord错误:
Art Load (18.4ms) SELECT "arts".* FROM "arts" GROUP BY user_id ORDER BY created_a
我有一个Ruby on Rails条件,它可以在MySQL中工作,但不能在PostGres中工作
:conditions => ["A between ? and ? and B between ? and ? and C between ? and ? and ddd is ?",@amin,@amax,@bmin,@bmax,@cmin,@cmax,params[:input].to_s]
生成错误:
ActiveRecord::StatementInvalid (PGError: ERROR: syntax error at or near "E'
我阅读/学习“敏捷开发..”现在我在第14章(测试)/
当我尝试运行"@ruby -I测试测试/单元/product_TEST.rb“时,我遇到错误
1) Error:
test_invalid_with_empty_attributes(ProductTest):
ActiveRecord::StatementInvalid: PGError: ERROR: relation "carts" does not exist
LINE 1: DELETE FROM "carts"
^
: DELETE FROM &
如何格式化日期以将其放入factory_girl_rails工厂中,例如:
Factory.define(:profile) do |t|
t.length 110
t.shipdate 1993-04-06
end
如果重要的话,我正在使用postgresql和factory_girl_rails 1.0。我得到的错误是ActiveRecord::StatementInvalid: PGError: ERROR: invalid input syntax for type date: "1982",rails版本是3.1
获取错误:
ActiveRecord::StatementInvalid (PGError: ERROR: argument of HAVING must be type boolean, not type timestamp without time zone
控制器代码片段:
def inactive
@number_days = params[:days].to_i || 90
@clients = Client.find(:all,
:include => :appointments,
:conditions => ["c
我正在尝试运行如下所示的sql
select name from appointments where location_id in (2,3,4)
以下内容不起作用。我正在使用PostgreSQL
a = [2,3,4]
Appointment.select(:name).where("location_id IN ?", a)
ActiveRecord::StatementInvalid: PGError: ERROR: syntax error at or near "2"
LINE 1: ... FROM "appointment
我希望我的报告显示在CST,而我的数据库在协调世界时。为此,我需要能够按时间列进行分组,并进行db do时区转换。
这适用于我的dev postgresql框:
offset = -5
result = ActiveRecord::Base.connection.execute("select date(srl.created_at AT TIME
ZONE '#{offset.to_s}') AS date, count(*) from server_request_logs srl where
srl.created_at
我只是尝试运行一个查询来查找数据库中"datetime“列中的值小于当前unix时间戳的所有记录。
目前这是我的代码。它在本地运行得很好。
t = Time.new.to_i
Event.where("datetime < #{t}")
当我在heroku控制台中测试它时,我得到了这个错误。
>> Event.where("datetime < #{t}")
ActiveRecord::StatementInvalid: PGError: ERROR: operator does not exist: character var
我是Rails的新手和编写测试。其中一些会生成异常;我希望"rake测试“输出能够给出异常错误消息,而不是整个回溯。(我想编写练习未实现功能的测试,然后我将填写这些测试。)
例如,实际产出:
Started
E
Finished in 0.081054 seconds.
1) Error:
test_should_fail(VersioningTest):
ActiveRecord::StatementInvalid: PGError: ERROR: null value in column "client_ip" violates not-null const
我在PostgreSQL上运行遇到了问题(它在SQLite上运行得很好)。
下面是一个错误示例:
>> Annotation.creations_report
ActiveRecord::StatementInvalid: PGError: ERROR: operator does not exist: ` character varying
LINE 1: ... grouping = E'day' AND aggregation = E'count' AND `condition...
当我尝试运行时:
heroku run rake db:drop db:create db:migrate
我得到了错误:
Running rake db:drop attached to terminal... up, run.5
Couldn't drop adsfsadfas : #<ActiveRecord::StatementInvalid: PGError: ERROR: must be owner of database adsfsadfas
: DROP DATABASE IF EXISTS "adsfsadfas">
我在Heroku雪松
在迁移到heroku的过程中,我只有在使用PostgreSQL时才会出现奇怪的错误(在Mysql中运行良好)。
当我执行@user.county_ids时,我得到以下错误:
ActiveRecord::StatementInvalid: PGError: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
LINE 1: ...id" WHERE ("activity_areas".user_id = 1) ORDER BY counties.n...
生成的sql请求
可能重复:
当我的代码试图在heroku上的数据库中插入大数字(如100001857905525 )时,我会得到以下错误:
ActiveRecord::StatementInvalid (PGError: ERROR: integer out of range )
列已定义为整数。我使用sqlite3数据库。我的代码被部署到heroku。
当我在本地主机上运行时,它工作得很好。但是,只有在heroku上运行代码时,我才会得到上述错误。也许我可以通过将列定义为长整数或双列来解决这个问题。我如何在Ruby/Rails中做到这一点?
我的状态模型如下所示:
class State < ActiveRecord::Base
belongs_to :country
named_scope :order_by_name, :order => :name
validates_presence_of [:country, :name]
def <=>(other)
name <=> other.name
end
end
我的国家模型是这样的:
class Country < ActiveRecord::Base
has_many :states
na
我想使用Rails 3和一个查询来选择有一个或多个注释的帖子。
我试着做这样的事:
Post.includes(:comments).where('count(comments.id)>0')
然而,我得到了这个错误:
ActiveRecord::StatementInvalid: PGError: ERROR: aggregates not allowed in WHERE clause
我搜索过这个和类似的方法,分组,等等,没有运气。任何帮助都将不胜感激。
我已经设置了一个系统,自动从我的Heroku部署的rails应用程序下载并存储数据库转储。一切正常,但是当我下载转储文件并将其恢复到本地postgres服务器,然后尝试在恢复的数据库上运行我的本地应用程序时,我收到以下错误
ActiveRecord::StatementInvalid in HomeController#index
PGError: ERROR: permission denied for relation users : SELECT "users".* FROM "users" WHERE ("use
我正在尝试将AuthLogic集成到我的rails应用程序中,并且遵循了将persistence_token定义为字符串的示例:
然而,当我在我的PostgreSQL桌面上用ubuntu 8.4运行它时,我得到了以下错误:
ActiveRecord::StatementInvalid in UsersController#index
PGError: ERROR: operator does not exist: character varying = integer
LINE 1: ...* FROM "users" WHERE ("users".