Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

optional feature `uuid` required for type UUID of column #1 ("id")

Tags:

rust

rust-sqlx

I'm trying to query a PostgreSQL database table using sqlx. But, the following error is shown

[rustc] [E] optional feature `uuid` required for type UUID of column #1 ("id")

My code snippet

use sqlx::{Pool, Postgres, postgres::PgRow, Row, FromRow};
use uuid::Uuid;

#[derive(FromRow)]
struct User {
    id: uuid::fmt::Hyphenated 
}

let result = sqlx::query_as!(User, "SELECT id FROM users")
    .fetch_one(pool)
    .await
    .expect("QUERY FAILED");

SQL

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

CREATE TABLE IF NOT EXISTS users (
    id uuid DEFAULT uuid_generate_v4(),
    PRIMARY KEY (id)
);

Any idea how to resolve an error?

like image 721
Roman Mahotskyi Avatar asked Oct 19 '25 20:10

Roman Mahotskyi


1 Answers

It turned out that I did not add a flag "uuid" in the Cargo.toml file

- sqlx = { version = "0.5", features = [ "runtime-actix-native-tls" , "postgres" ] }
+ sqlx = { version = "0.5", features = [ "runtime-actix-native-tls" , "postgres", "uuid" ] }

P.S.

Looks like I was using a different type of UUID.

I had the Uuid crate installed separately, but it required the Uuid from sqlx (eg sxl::types::Uuid).

like image 50
Roman Mahotskyi Avatar answered Oct 22 '25 10:10

Roman Mahotskyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!