Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Range element query fails with WrongType when parameterised #1258

Open
@itowlson

Description

@itowlson

I'm running into a problem when trying to use the "element contained in range" (<@) query operator when the element is passed as a query parameter. The query is rejected for WrongType. Here is an example.

I set up the table and data as follows:

create table rangetest(id int, r int4range);insert into rangetest(id, r) values(1, '[1, 10]');

When I run an "element in range" query in Rust, it succeeds, but when I parameterise the5 value, it fails:

use tokio_postgres::NoTls;#[tokio::main]async fn main() {    let (client, conn) = tokio_postgres::connect("host=localhost user=postgres password=*** dbname=mydb", NoTls).await.unwrap();    tokio::spawn(async move { conn.await.unwrap(); });  // keep conn alive    // This succeeds    let rs = client.query("select id from rangetest where 5 <@ r", &[]).await.unwrap();    println!("{rs:?}");    // This fails with WrongType    let rs = client.query("select id from rangetest where $1 <@ r", &[&5i32]).await.unwrap();    println!("{rs:?}");}

The output shows the query with a literal value succeeding, and the query with the parameter failing:

[Row { columns: [Column { name: "id", table_oid: Some(24576), column_id: Some(1), type: Int4 }] }]thread 'main' panicked at src/main.rs:56:85:called `Result::unwrap()` on an `Err` value: Error { kind: ToSql(0), cause: Some(WrongType { postgres: Int4Range, rust: "i32" }) }

I'm on tokio-postgres 0.7.13, Rust 1.86, PostgreSQL 16.3, Ubuntu 22 on WSL. Let me know if I can provide any more diagnostic information - and apologies in advance if this is already known, I failed to find an issue for it. Thanks!

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp