Skip to content

rust-postgres setting timezone to UTC on connecting is not appropriate #608

@jmafc

Description

@jmafc

If you issue the query SELECT CURRENT_TIMESTAMP in psql 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 the timezone parameter in postgresql.conf). In psql the value returned shows the timezone adjustment to UTC, e.g., if the timezone in postgresql.conf is set to America/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.

let mut params = vec![("client_encoding", "UTF8"), ("timezone", "UTC")];
This not only affects the values of the query above but any query that depends on the server's notion of "local time". For example, if a website shows a different result, based on whether it's past midnight in the local sense (i.e., based on the Postgres server's actual timezone location), if retrieved via rust-postgres the results will change starting at 0:00 UTC, e.g., possibly eight/seven hours earlier than desired if the server is located in the Pacific timezone. The only workaround is for the client to send a 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").

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions