Ruby on rails 使用ActiveRecord在外部数据库中执行函数/存储过程
我正在尝试从Rails 4应用程序在外部PostgreSQL数据库中执行一个函数。我不知道怎么做 我正在连接外部数据库,如下所示:Ruby on rails 使用ActiveRecord在外部数据库中执行函数/存储过程,ruby-on-rails,postgresql,ruby-on-rails-4,activerecord,Ruby On Rails,Postgresql,Ruby On Rails 4,Activerecord,我正在尝试从Rails 4应用程序在外部PostgreSQL数据库中执行一个函数。我不知道怎么做 我正在连接外部数据库,如下所示: class Pgdb < ActiveRecord::Base self.abstract_class = true establish_connection :pg_development end class Mytable < Pgdb self.table_name = 'mytable' end 我不知道如何执行存储过程,因为它不
class Pgdb < ActiveRecord::Base
self.abstract_class = true
establish_connection :pg_development
end
class Mytable < Pgdb
self.table_name = 'mytable'
end
我不知道如何执行存储过程,因为它不是表。即使我试图设置self.table_name=my_存储_过程并查询@info=Mytable.connection.executeexecute my_存储_过程“{params[:name]}”。它给出了一个错误:error:prepared语句my_存储过程不存在
我也尝试过:
@info = Pgdb.connection.execute("execute my_stored_procedure('#{params[:name]}')")
ERROR> PG::InvalidSqlStatementName: ERROR: prepared statement "my_stored_procedure" does not exist : execute agg_backs('JOHNSON, WALTER, PORTRAIT')
@info = Pgdb.execute("execute my_stored_procedure('#{params[:name]}')")
ERROR> undefined method `execute' for Pgdb(abstract):Class
如何执行我的存储过程?您需要以与从psql(选择我的存储过程)调用它相同的方式调用它。读《谢谢》是值得的!成功了。我知道在SQL中是这样做的,但有时在ActiveRecord中是不同的。我也遇到同样的问题。实际上,在Postgres中,您使用SELECT^^^调用它的方式与从psql调用它的方式相同,psql是SELECT my_storaged_procedureprams。读《谢谢》是值得的!成功了。我知道在SQL中是这样做的,但有时在ActiveRecord中是不同的。我也遇到同样的问题。实际上,在Postgres中,您使用SELECT^^
@info = Pgdb.connection.execute("execute my_stored_procedure('#{params[:name]}')")
ERROR> PG::InvalidSqlStatementName: ERROR: prepared statement "my_stored_procedure" does not exist : execute agg_backs('JOHNSON, WALTER, PORTRAIT')
@info = Pgdb.execute("execute my_stored_procedure('#{params[:name]}')")
ERROR> undefined method `execute' for Pgdb(abstract):Class