Skip to content

rust sqlx访问时ColumnNotFound错误 #294

Description

@Arteez-gif

rust版本:rustc 1.90.0 (1159e78c4 2025-09-14
sqlx版本:v0.8.0

let db_url = "mysql://xxx:xxx@host:port?ssl-mode=disabled";
let conn_options = MySqlConnectOptions::from_str(db_url)?
.disable_statement_logging()
.no_engine_subsitution(false)
.pipes_as_concat(false)
.timezone(None)
.charset("utf8mb4")
.collation("utf8mb4_unicode_ci")
.set_names(false);

let sql: &'static str = "SELECT * from xxx.xx";
let mut rows = sqlx::query(sql)
.fetch_all(&conn_pool).await?;

for row in &rows {
let col_name: &'static str = "TEST_COLUMN";
let test_column: String = row.try_get(col_name)?;
println!("{}", test_column);
}
连接gaea执行这种普通的SQL语句,会报错Error: ColumnNotFound('TEST_COLUMN')。

  1. 但是直接连接mysql节点执行没有问题。
  2. let test_column: String = row.try_get(col_name)?;
    改为let test_column: String = row.try_get(0)try_get参数中使用正确的列索引也能正确执行。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions