Skip to content

SET TIME ZONE in Pool creation doesn't work #3038

Closed as not planned
Closed as not planned
@frederikhors

Description

@frederikhors

As explained here I'm using the below code:

use sqlx::Executor;
use sqlx::postgres::PgPoolOptions;

let pool = PgPoolOptions::new()
  .after_connect(|conn, _meta| Box::pin(async move {
    conn.execute("SET TIME ZONE 'Europe/Berlin';").await?;

    let result: (time::OffsetDateTime,) = sqlx::query_as("SELECT current_timestamp").fetch_one(conn).await?;

    println!("Current Time in Europe/Berlin: {}", result.0);

    Ok(())
  }))
  .connect("postgres:// …").await?;

and the result is:

Current Time in Europe/Berlin: 2024-02-06 22:39:37.194022 +00:00:00

which is wrong because the current Berlin time is "23" not "22" (which is UTC).

My database is currently on UTC by default (from postgresql.conf file).

And it works if I use the below code in a Postgresql query:

SET TIME ZONE 'Europe/Berlin';
SELECT current_timestamp;

Where am I wrong?

Info

  • SQLx version: 0.7.3
  • SQLx features enabled: "macros", "postgres", "runtime-tokio", "time"
  • Database server and version: Postgres v16.1
  • Operating system: Windows 10
  • rustc --version: rustc 1.75.0 (82e1608df 2023-12-21)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions