-
-
Notifications
You must be signed in to change notification settings - Fork 434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rust-postgres setting timezone to UTC on connecting is not appropriate #608
Comments
This is necessary to enable conversion of types to and from time datatypes. If you aren't using those, you can set your own timezone via the |
I am using the conversions, but I'm not sure why overriding the server's notion of its timezone is needed to convert timestamps. In |
The timezone offset is not included in the binary encoding of the values. |
I find that hard to believe. Do you have a doc or source reference? The internal time defined in |
You would have to ask the postgres developers. |
I did ask and Tom Lane replied (https://www.postgresql.org/message-id/1375425.1591317171%40sss.pgh.pa.us) that the binary format, as the on-disk format, doesn't include the offset (which makes sense because internally the server operates in UTC where the offset is zero). However, if a timezone is set, config.options("-c 'SET timezone=\'America/New_York\';"); The equivalent string in |
@jmafc the As far as I'm aware rust-postgres only makes use of the more efficient and more flexible binary PostgreSQL protocol. FWIW, having your application behaviour depend on the system timezone configured on your database server seems a rather brittle approach. If midnight in a particular timezone is important to your application, then it may be a better idea to explicitly convert UTC timestamps to that time zone (you can do it in the database easily using |
The binary may be "more efficient" but I don't think using it exclusively is the right approach precisely because it detracts from the flexibility desired by some users. |
If you issue the query
SELECT CURRENT_TIMESTAMP
inpsql
or from other language adapters such as psycopg2, the Postgres server will return a value adjusted to what it considers its timezone (specifically, based on the value in thetimezone
parameter inpostgresql.conf
). Inpsql
the value returned shows the timezone adjustment to UTC, e.g., if thetimezone
inpostgresql.conf
is set toAmerica/Denver
(MST), then the value is suffixed with-07
(or-06
during DST).rust-postgres overrides this normal situation by sending
timezone=UTC
when connecting to the server.rust-postgres/tokio-postgres/src/connect_raw.rs
Line 114 in 2ce4f08
SET TIMEZONE timezone-value
query before sending such a time-sensitive query.Therefore I think the timezone parameter should not be sent at all, or if sent, it should be configurable (with the default being "don't send it").
The text was updated successfully, but these errors were encountered: