Execute a prepared statement in Rails
The PostgreSQLAdapter
in rails has a method called #exec_query
that allows you to use prepared statements with bind variables:
User.connection.exec_query(
"select * from users where email = $1",
nil,
["a@example.com"],
prepare: true
)
Will issue:
select * from users where email = $1 [[nil, "a@example.com"]]
Tweet