Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用ActiveRecord在外部数据库中执行函数/存储过程_Ruby On Rails_Postgresql_Ruby On Rails 4_Activerecord - Fatal编程技术网

Ruby on rails 使用ActiveRecord在外部数据库中执行函数/存储过程

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 我不知道如何执行存储过程,因为它不

我正在尝试从Rails 4应用程序在外部PostgreSQL数据库中执行一个函数。我不知道怎么做

我正在连接外部数据库,如下所示:

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