You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CREATETABLEtest (
id varchar(64) PRIMARY KEY,
name textNOT NULL
);
Also let's say I have three query options:
asyncfnsql1(session:&mutTransaction<'_,Postgres>) -> sqlx::Result<()>{let rows = sqlx::query!(r#"SELECT id AS "id: i64", name AS "name: i64" FROM test"#).fetch_all(&mut**session).await?;Ok(())}asyncfnsql2(session:&mutTransaction<'_,Postgres>) -> sqlx::Result<()>{structRow{id:i64,name:i64,}let rows = sqlx::query_as!(Row,r#"SELECT id, name FROM test"#).fetch_all(&mut**session).await?;Ok(())}asyncfnsql3(session:&mutTransaction<'_,Postgres>) -> sqlx::Result<()>{structRow{id:i64,name:i64,}let rows = sqlx::query_as!(Row,r#"SELECT id AS "id: i64", name AS "name: i64" FROM test"#).fetch_all(&mut**session).await?;Ok(())}
Why does only option 2 fail?
--> src/main.rs:16:16
|
16 | let rows = sqlx::query_as!(Row, r#"SELECT id, name FROM test"#)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `From<std::string::String>` is not implemented for `i64`, which is required by `std::string::String: Into<_>`
|
At the same time, in documentation the following is written:
If you select a column foo as "foo: _" (Postgres/SQLite) or foo as `foo: _` (MySQL) it causes that column to be inferred based on the type of the corresponding field in the given record struct. Runtime type-checking is still done so an error will be emitted if the types are not compatible.
Reproduction steps
See code snippet in description
SQLx version
0.8.3
Enabled SQLx features
"runtime-tokio-rustls", "postgres"
Database server and version
Postgres 15.7
Operating system
Ubuntu 20.04
Rust version
1.84.1
The text was updated successfully, but these errors were encountered:
zshell31
changed the title
Strange behavior when inferring types for queries
query!(..)/query_as!(..) strange behavior when inferring types for queries
Feb 11, 2025
I have found these related issues/pull requests
I found only issues related to inferring types for nullable fields
Option
NULLable-types #1852Description
Let's say I have the following table in Postgres:
Also let's say I have three query options:
Why does only option 2 fail?
At the same time, in documentation the following is written:
Reproduction steps
See code snippet in description
SQLx version
0.8.3
Enabled SQLx features
"runtime-tokio-rustls", "postgres"
Database server and version
Postgres 15.7
Operating system
Ubuntu 20.04
Rust version
1.84.1
The text was updated successfully, but these errors were encountered: