How do you execute a SQL statement from Rails 3?
For example, the SQL statement "SELECT CURRENT_TIME" gets the time (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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.