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
In two different environments (for example, Test and Prod environments), when the order of fields in a table is inconsistent, using select * from table can lead to misplacement of field values or, in more severe cases, a panic.
This is a very serious potential issue. It should be explicitly stated in the documentation that data must be accessed using field names, not by using select * from.
Info
SQLx version: 0.7.3
SQLx features enabled: "postgres", "runtime-tokio", "json", "macros", "time", "rust_decimal",
#[derive(Debug)]structUser{id:i32,name:String,age:i32,}#[tokio::main]asyncfnmain(){
dotenvy::dotenv().ok();let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");let pool = sqlx::PgPool::connect(&database_url).await.unwrap();let users = sqlx::query_as!(User,"select * from test_user").fetch_all(&pool).await.unwrap();println!("{:?}", users);}
Test & Ooutput:
test=> \d test_user
Column | Type | Collation | Nullable | Default
--------+-------------------+-----------+----------+---------
id | integer | | not null |
name | character varying | | not null |
age | integer | | not null |
[User { id: 1, name: "test", age: 19 }]
Prod & Output:
prod=> \d test_user
Column | Type | Collation | Nullable | Default
--------+-------------------+-----------+----------+---------
id | integer | | not null |
age | integer | | not null |
name | character varying | | not null |
Bug Description
In two different environments (for example, Test and Prod environments), when the order of fields in a table is inconsistent, using select * from table can lead to misplacement of field values or, in more severe cases, a panic.
This is a very serious potential issue. It should be explicitly stated in the documentation that data must be accessed using field names, not by using select * from.
Info
rustc --version
: rustc 1.76.0 (07dca489a 2024-02-04)Minimal Reproduction
Test & Ooutput:
Prod & Output:
The text was updated successfully, but these errors were encountered: