0

I have a table toto which contains fields id uuid and name varchar. I want to insert data into it so I do:

use postgres::{Client, Error, NoTls};
use uuid::Uuid; 

fn main() -> Result<(), Error> {
   let mut client = Client::connect("host=localhost user=user dbname=dbname password='password'", NoTls)?;

   let id = Uuid::new_v4();
   client.execute(
       "INSERT INTO toto (id, name) VALUES ($1, $2)",
       &[&id, &"azert"],
   )?;
   Ok(())
}

In my Cargo.toml I have:

[dependencies]
uuid = { version = "0.8.2", features = ["v4"] }
postgres = { version = "0.19"}

and for the line :

&[&id, &"azert"],

and this gives me the following error:

the trait `ToSql` is not implemented for `Uuid`

How do I resolve this?

E_net4
  • 27,810
  • 13
  • 101
  • 139
tyler
  • 13
  • 6
  • Add the `with-uuid-0_8` Cargo feature in `postgres` for the capability to map `Uuid` to a database type. – E_net4 Feb 14 '23 at 09:30

0 Answers0