0

I wanted to upload a polars dataframe to postgres using diesel. In that insert_into() function is there, where i have to give tuple of vectors as an input to .values().

Can anyone give suggestion on how to upload that.

pub fn insert_tuple_batch(conn: &mut PgConnection) -> Result<()> {
    use schema::users::dsl::*;
    insert_into(users)
        .values(&vec![
            (
                id.eq(1),
                title.eq("Sean"),
                body.eq("Black"),
                published.eq(true),
            ),
            (
                id.eq(2),
                title.eq("Tess"),
                body.eq("Brown"),
                published.eq(true),
            ),
        ])
        .execute(conn)
        .expect("Not inserted");
    println!("insert completed");
    Ok(())
}

I have id, title, body and published columns in a polars dataframe. I need to access the dataframe to convert to this.

&vec![
    (
        id.eq(1),
        title.eq("Sean"),
        body.eq("Black"),
        published.eq(true),
    ),
    (
        id.eq(2),
        title.eq("Tess"),
        body.eq("Brown"),
        published.eq(true),
    ),
]

where datatypes of columns are:

pub id: i32,  //Int4
pub title: String,  //Varchar
pub body: String,  //Text
pub published: bool,  //Bool

I have id, title, body and published columns in a polars dataframe. I need to access the dataframe to convert to this.

&vec![
    (
        id.eq(1),
        title.eq("Sean"),
        body.eq("Black"),
        published.eq(true),
    ),
    (
        id.eq(2),
        title.eq("Tess"),
        body.eq("Brown"),
        published.eq(true),
    ),
]

where datatypes of columns are:

pub id: i32,  //Int4
pub title: String,  //Varchar
pub body: String,  //Text
pub published: bool,  //Bool
Holloway
  • 6,412
  • 1
  • 26
  • 33
  • You posted a bunch of additional info as answers. If you want to add additional info to the question please [edit](https://stackoverflow.com/posts/74531953/edit) it instead and delete all non answers. There is also some dplication which you cold remove while you're at ti. – cafce25 Nov 22 '22 at 12:25

0 Answers0