From 97bee1d38f91f45109bac9af03e2775e4d01d210 Mon Sep 17 00:00:00 2001 From: johnbrk Date: Tue, 31 Mar 2026 15:29:24 -0400 Subject: [PATCH 1/2] fix:/prefer the use of column identity over ordinals --- sqlx-macros-core/src/query/output.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/sqlx-macros-core/src/query/output.rs b/sqlx-macros-core/src/query/output.rs index 987dcaa3cb..49d872cd3a 100644 --- a/sqlx-macros-core/src/query/output.rs +++ b/sqlx-macros-core/src/query/output.rs @@ -146,17 +146,24 @@ pub fn quote_query_as( |( i, RustColumn { - var_name, type_, .. + var_name, type_, ident }, )| { match (input.checked, type_) { // we guarantee the type is valid so we can skip the runtime check - (true, ColumnType::Exact(type_)) => quote! { - // binding to a `let` avoids confusing errors about - // "try expression alternatives have incompatible types" - // it doesn't seem to hurt inference in the other branches - #[allow(non_snake_case)] - let #var_name = row.try_get_unchecked::<#type_, _>(#i)?.into(); + (true, ColumnType::Exact(type_)) => { + let column_ident = quote::format_ident!("{}", ident); + + quote! { + // binding to a `let` avoids confusing errors about + // "try expression alternatives have incompatible types" + // it doesn't seem to hurt inference in the other branches + #[allow(non_snake_case)] + let #var_name = row.try_get_unchecked::<#type_, _>( + // use the column identity as the index, + stringify!(#column_ident) + )?.into(); + } }, // type was overridden to be a wildcard so we fallback to the runtime check (true, ColumnType::Wildcard) => quote! ( From 159752561bbe7558a154f0f957fc6c0b4b0d1552 Mon Sep 17 00:00:00 2001 From: johnbrk Date: Tue, 31 Mar 2026 16:58:18 -0400 Subject: [PATCH 2/2] fix:/ formatting --- sqlx-macros-core/src/query/output.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sqlx-macros-core/src/query/output.rs b/sqlx-macros-core/src/query/output.rs index 49d872cd3a..47320c6272 100644 --- a/sqlx-macros-core/src/query/output.rs +++ b/sqlx-macros-core/src/query/output.rs @@ -146,7 +146,9 @@ pub fn quote_query_as( |( i, RustColumn { - var_name, type_, ident + var_name, + type_, + ident, }, )| { match (input.checked, type_) { @@ -164,7 +166,7 @@ pub fn quote_query_as( stringify!(#column_ident) )?.into(); } - }, + } // type was overridden to be a wildcard so we fallback to the runtime check (true, ColumnType::Wildcard) => quote! ( #[allow(non_snake_case)]