[英]How to get time from database in Rails?
How do you execute a SQL statement from Rails 3?如何从 Rails 3 执行 SQL 语句?
For example, the SQL statement "SELECT CURRENT_TIME" gets the time (working in PostgreSQL).例如,SQL 语句“SELECT CURRENT_TIME”获取时间(在 PostgreSQL 中工作)。
Model.find_by_sql("SELECT CURRENT_DATE")
returns a model object. Model.find_by_sql("SELECT CURRENT_DATE")
返回 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 。
sql = "SELECT CURRENT_TIME"
ActiveRecord::Base.connection.select_value(sql)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.