Skip to content

sqlx query's output is different when the same query is run from postgresql cli #3226

Open
@ItsEthra

Description

@ItsEthra

Bug Description

When running the query using sqlx, its output is different vs when the same query is run using postgersql CLI. Postgresql server, database are the same.

Minimal Reproduction

let out = sqlx::query!(
    "
        SELECT
            date_trunc('day', '2024-05-09 01:00:00+03'::timestamptz) as foo,
            date_trunc('day', '2024-05-09 16:22:19.553755+03'::timestamptz) as bar,
            (
                date_trunc('day', '2024-05-09 01:00:00+03'::timestamptz) =
                date_trunc('day', '2024-05-09 16:22:19.553755+03'::timestamptz)
            ) as eq
    "
)
.fetch_one(&state.db)
.await?;
dbg!(out);

Output:

out = Record {
    foo: Some(
        2024-05-08 0:00:00.0 +00:00:00,
    ),
    bar: Some(
        2024-05-09 0:00:00.0 +00:00:00,
    ),
    eq: Some(
        false,
    ),
}

If the same query is run against the same database on the same postgresql server using psql:

          foo           |          bar           | eq
------------------------+------------------------+----
 2024-05-09 00:00:00+03 | 2024-05-09 00:00:00+03 | t
(1 row)

Interestingly enough, if AT TIME ZONE 'UTC' is applied to both timestamps before truncating, or UTC argument is supplied to date_trunc function, output will be the same between sqlx and psql.

Info

  • SQLx version: 0.7.4
  • SQLx features enabled: postgres,time,uuid,runtime-tokio,rust_decimal
  • Database server and version: Postgresql 16.2
  • Operating system: Arch linux 6.8.9-zen1-2-zen
  • rustc --version: rustc 1.79.0-nightly (ab5bda1aa 2024-04-08)

Metadata

Metadata

Assignees

No one assigned

    Labels

    db:postgresRelated to PostgreSQLdocumentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions