Here is a query result from Postgres:
$ psql ... -c 'select the_date from foo where foo_id in (998,999)'
the_date
------------------------
2012-03-07 09:34:47.98
2012-03-16 11:31:25.336
the_date is “timestamp without time zone”.
Here is a Ruby program:
#!/usr/bin/env ruby
require 'sequel'
@DB = Sequel.connect({...})
query = "select the_date from foo where foo_id in (998,999)"
@DB[query].each do |row|
warn row
end
and some output:
{:the_date=>2012-03-07 09:34:47 -0600}
{:the_date=>2012-03-16 11:31:25 -0500}
Where does the -0500 and -0600 come from? That is the “Olson timezone” of the server and the client machines (US/Central), but why does Ruby add it and psql does not?
I’ve been reading the docs, and I’m thoroughly confused.
The server is Postgres 9.0.4, the client is psql 9.1.4, sequel is 3.33.0.
The column is of type ‘timestamp without timezone’. Thus when Postgres displays a value in this column it just displays the timestamp with no timezone. However, Sequel wants to convert a Postgres timestamp to an instance of the Ruby Time class, and an instance of the Time class must have a timezone specified – either it’s a time in the local timezone or it’s a time in UTC. Thus Sequel must choose one. By default, it’s choosing your local timezone.
You may configure the database and application timezone in Sequel. See https://www.rubydoc.info/gems/sequel/4.36.0/Sequel/Timezones
For example, here’s the default Sequel behavior with a database I had handy:
Here the timestamp is assumed to be in my local timezone (EDT).
However, if I do this:
Then the timestamp is assumed to be in UTC.