I created a Postgres function that I use to execute a complex query that combines many tables that all should be filtered by a dynamic date field.
The function works fine and allows me to execute a query like "SELECT * FROM trail_for_date('2014-01-01')" and returns a table.
A simplified example from the Postgres documentation on functions:
CREATE FUNCTION sum_n_product_with_tab (x int) RETURNS TABLE(sum int, product int) AS $$ SELECT $1 + tab.y, $1 * tab.y FROM tab; $$ LANGUAGE SQL;
How can I use this return table as a Rails / Ruby model where the function argument is dynamic?
Something like the following (which obviously doesn't work):
class SimplifiedExample < ActiveRecord::Base self.table_name = 'sum_n_product_with_tab(:dynamic_input)' end
ruby-on-rails postgresql ruby-on-rails-3
Helios de guerra
source share