Trying to execute a POSTGRESQL stored procedure/function in Ruby Grape API Package. I have the function getactivesites() in my server which returns the site name.
server code:
BEGIN
RETURN QUERY SELECT "SITE_ID",
"SITE_NAME"
FROM public.sites WHERE "ACTIVE_FLAG" = true
ORDER BY "SITE_NAME" ASC ;
END;
ruby code:
resource :getsites do
desc “Get Active Sites“
get do
results = ActiveRecord::Base.connection.execute("execute getactivesites")
return results
end
The error I get when I run it is “PG::InvalidSqlStatementName: ERROR: prepared statement "getactivesites" does not exist : execute getactivesites”
getactivesitesprocedure work if you run it directly in the postgres console?ActiveRecord::Base.connectionis connecting to, when that line executes, in whatever context you are seeing the failure.