rubypostgresqltimezonesequel-gem

How to make TIMESTAMP WITH TIME ZONE column with Ruby Sequel?


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?


Solution

  • 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.