Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Type override together with wildcard does not work

オープン
#4,151 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
28/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
postgresql, rust, sql
領域
databases, tooling

調査の方向性

The failure is in the sqlx::query_as! expansion ($crate::sqlx_macros::expand_query) when SELECT users.* is combined with an explicit id as "id: UserId" override, then cargo sqlx prepare / cargo check. Start from how the prepare/check path maps SQL columns onto the MyUser struct and how wildcard columns are merged with type overrides. Done when that query compiles and prepare succeeds without E0062 duplicate id.

索引モデルが issue の本文から書いたものです。

説明

bug
I have found these related issues/pull requests

None directly for this issue.

Description

Overriding the type for a subset of columns, as shown in Compile-time verification example from docs, does not work with cargo sqlx prepare.

Reproduction steps
CREATE TABLE users
(
    id BIGINT NOT NULL PRIMARY KEY,
    name TEXT NOT NULL
);
#[derive(sqlx::Type)]
#[sqlx(transparent)]
struct UserId(i64);

struct MyUser { id: UserId, name: String }

async fn sql(conn: &mut sqlx::PgConnection) {
    // fetch all properties from user and override the type in Rust for `id`
    let user = sqlx::query_as!(MyUser, r#"SELECT users.*, id as "id: UserId" FROM users"#)
        .fetch_one(conn).await.unwrap();
}
$ cargo sqlx prepare
    Checking sqlx-test v0.1.0 (/sqlx-test)
error[E0062]: field `id` specified more than once
 --> src/main.rs:9:16
  |
9 |     let user = sqlx::query_as!(MyUser, r#"SELECT users.*, id as "id: UserId" FROM users"#)
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |                |
  |                used more than once
  |                first use of `id`
  |
  = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0062`.
error: could not compile `sqlx-test` (bin "sqlx-test") due to 1 previous error
error: `cargo check` failed with status: exit status: 101
SQLx version

0.8.6

Enabled SQLx features

runtime-tokio, postgres

Database server and version

Postgres 16.3

Operating system

Ubuntu 24.04

Rust version

1.93.0

主要言語
Rust
スター
17.5k
フォーク
1.7k
平均マージ
1日 10時間
マージ済み PR(30日)
6

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

transact-rs/sqlx のほかの issue

transact-rs/sqlx の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。