2

I am learning Ruby and Sequel, and trying to make some table.

I want to save my time value as in UTC in PostgreSQL database. So I made a table with

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?

eonil
  • 83,476
  • 81
  • 317
  • 516

1 Answers1

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.

Jeremy Evans
  • 11,959
  • 27
  • 26
  • If I don't do `Sequel.default_timezone = :utc`, will Sequel perform UTC(in DB) <-> local(in Ruby) conversion? If it handles it automatically, it would be also nice. – eonil Mar 07 '13 at 00:56
  • It may do that, it may not. If you want to enforce that behavior `Sequel.database_timezone = :utc` and `Sequel.application_timezone = :local`. – Jeremy Evans Mar 07 '13 at 16:05