How do you execute a SQL statement from Rails 3?
For example, the SQL statement "SELECT CURRENT_TIME" gets the ti开发者_如何学运维me (working in PostgreSQL).
Model.find_by_sql("SELECT CURRENT_DATE")
returns a model object.
If you want to do what you are asking you can get a handle to the connection and just execute sql on it.
sql = "SELECT CURRENT_TIME"
ActiveRecord::Base.connection.select_value(sql)
精彩评论