I am learning Ruby and Sequel, and trying to make some table.
我正在学习Ruby和Sequel,并尝试做一些表格。
I want to save my time value as in UTC in PostgreSQL database. So I made a table with
我想将时间值保存为PostgreSQL数据库中的UTC。所以我做了一张桌子
db.create_table :TestTable1 do
Timestamp :field1
end
but I got
但是我有
field1 | timestamp without time zone | | plain |
I want my value in database to have strict basis. So I want to force everything in UTC. I think there should be a way to make TIMESTAMP WITH TIME ZONE
column. How can I do this?
我希望我在数据库中的值具有严格的基础。所以我想让所有东西都在UTC。我认为应该有办法用时区列做时间戳。我该怎么做呢?
1 个解决方案
#1
6
When creating the table, you can specify specific types:
在创建表时,可以指定特定类型:
db.create_table :TestTable1 do
column :field1, 'timestamp with time zone'
end
You probably want to use Sequel.default_timezone = :utc
as well, but that doesn't affect how times are actually stored in the database.
您可能希望使用Sequel.default_timezone =:utc,但这并不影响实际存储在数据库中的时间。
#1
6
When creating the table, you can specify specific types:
在创建表时,可以指定特定类型:
db.create_table :TestTable1 do
column :field1, 'timestamp with time zone'
end
You probably want to use Sequel.default_timezone = :utc
as well, but that doesn't affect how times are actually stored in the database.
您可能希望使用Sequel.default_timezone =:utc,但这并不影响实际存储在数据库中的时间。