TIMESTAMPTZ columns are decoded without time zones, so I was trying to separate TIMESTAMP from TIMESTAMPTZ in TimeDecoder but discovered that Postgres transmits them over the wire identically, without time zone info, and found this comment with a source that corroborates that.
The psql client automatically transforms timestamps into the correct time zone based on the session/transaction's TIME ZONE setting. My thought was that we could do the same here. Maybe after connecting we could run something like @time_zone = query_one("SHOW TIME ZONE", as: String), and then TimeDecoder would run time.in(time_zone) for TSTZ columns, which would require passing the timezone somehow.
I'm not sure how we'd handle SET LOCAL TIME ZONE to set it for a transaction, though. We could maybe provide a Transaction#time_zone=(location : Time::Location) method, but I don't think the crystal-db shard supports driver-specific transactions yet so that would have to be a monkeypatch if we did it. If we don't provide a method for it, I don't know if we have a good way to detect the change.
TIMESTAMPTZ
columns are decoded without time zones, so I was trying to separateTIMESTAMP
fromTIMESTAMPTZ
inTimeDecoder
but discovered that Postgres transmits them over the wire identically, without time zone info, and found this comment with a source that corroborates that.The
psql
client automatically transforms timestamps into the correct time zone based on the session/transaction'sTIME ZONE
setting. My thought was that we could do the same here. Maybe after connecting we could run something like@time_zone = query_one("SHOW TIME ZONE", as: String)
, and thenTimeDecoder
would runtime.in(time_zone)
forTSTZ
columns, which would require passing the timezone somehow.I'm not sure how we'd handle
SET LOCAL TIME ZONE
to set it for a transaction, though. We could maybe provide aTransaction#time_zone=(location : Time::Location)
method, but I don't think thecrystal-db
shard supports driver-specific transactions yet so that would have to be a monkeypatch if we did it. If we don't provide a method for it, I don't know if we have a good way to detect the change.