ActiveRecord::Base.connection.execute(
"WITH numberofdays AS
(SELECT percent_change FROM asset_histories
WHERE date < $1
AND asset_symbol = $2
ORDER BY date DESC
LIMIT $3)
SELECT stddev_samp(percent_change) as stdev FROM numberofdays",
[day,symbol,daystolimit])
Where day, symbol and daystolimit are variables assigned before the above code. They are assigned as such:
day = '2013-03-25'
symbol = 'AAPL'
daystolimit = 20
I don't want to use #{variable} because of the potential for malicious intent.
As referenced in the title, my statement is returning
PGError ERROR: there is no parameter $1 LINE 1 ... WHERE date <$1 AND...
Using Postgresql 9.2 and rails 3.2
EDIT adding alternative solution I found here:
In addition to mu is too short where he uses connection.method(:quote), I couldn't find documentation on it so I came across another post where quoting was done as such:
a = ActiveRecord::Base.connection
a.execute(%Q{SELECT * FROM table WHERE id = #{a.quote(variable)}...})