sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

"optional sqlx feature `time` required for type TIMESTAMPTZ" needs to also suggest chrono

Open lf- opened this issue 6 months ago • 1 comments

I have found these related issues/pull requests

I have not found any, I just found a suggestion to support another time library.

Description

The following compiler error is generated while compiling a postgres query with the following sqlx features and chrono not enabled:

chrono = "0.4.41"
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio", "tls-rustls", "migrate", "uuid"] }
error: optional sqlx feature `time` required for type TIMESTAMPTZ of param #3
  --> storage/src/postgres/mod.rs:49:9
   |
49 | /         sqlx::query!(
50 | |             "insert into files (bucket, filename, delete_after, blob) values ($1, $2, $3, lo_create(0))",
51 | |             self.id,
52 | |             file_name,
53 | |             delete_after
54 | |         );
   | |_________^
   |
   = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the
 macro `sqlx::query` (in Nightly builds, run with -Z macro-backtrace for more info)

This error is wrong: it needs to mention the chrono feature.

Reproduction steps

Set up a sqlx with postgres then put the following code in a function:

async fn foo() {
  let now = chrono::Utc::now();
  sqlx::query!("select $1::timestamptz", now);
}

SQLx version

0.8.6

Enabled SQLx features

"postgres", "runtime-tokio", "tls-rustls", "migrate", "uuid"

Database server and version

Postgres 17.5

Operating system

macOS

Rust version

1.87.0

lf- avatar Jun 03 '25 19:06 lf-

To add to that. I have seen that with both time and chrono enabled, sqlx defaults to time when looking for some From implementations.

pronebird avatar Jun 12 '25 12:06 pronebird