1

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?

Roman Mahotskyi
  • 4,576
  • 5
  • 35
  • 68

1 Answers1

3

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).

Roman Mahotskyi
  • 4,576
  • 5
  • 35
  • 68