How to perform multiple insert with Vec<Option<String>> using Sqlx in Rust

266 Views Asked by At

I am trying to bulk insert some values using sqlx.

The problem now is some of these values can be null, so the types is

let ids: Vec<Option<String>> = ...

So when I construct the query like this

        sqlx::query!(
            r#"
            INSERT INTO products (id)
            SELECT *
            FROM UNNEST($1::text[])
            "#,
            &ids,
        ).execute(&self.pool)
            .await?;

It fails with the following error

    |
109 |             &ids
    |             ^
    |             |
    |             expected `&[String]`, found `&Vec<Option<String>>`
    |             expected due to the type of this binding
    |
    = note: expected reference `&[std::string::String]`
               found reference `&Vec<std::option::Option<std::string::String>>`

Any ideas how to do this?

0

There are 0 best solutions below