开发者

How to get time from database in Rails?

开发者 https://www.devze.com 2023-03-18 09:07 出处:网络
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).

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消