I was looking through the source code a bit, but wasn't certain if UUID is a natively supported field.
I have some basic tables that look like this:
CREATE TYPE operation AS ENUM ('create', 'update', 'delete');
CREATE TABLE IF NOT EXISTS events (
event_id uuid PRIMARY KEY NOT NULL, -- id of event
namespace uuid NOT NULL, -- user's "namespace" where their events are stored
event_time bigint NOT NULL, -- when event occurred
op operation NOT NULL, -- operation that occurred
acted_on uuid NOT NULL -- key of item that was acted on
);
I'm trying to do a test query on it to see if the whole setup works. I have a local instance of the db set up, and the DATABASE_URL properly set, but when I compile I get an error from some pretty simple code:
async fn get_all_in_ns(pool: PgPool) -> anyhow::Result<()> {
let rows = sqlx::query!(
r#"SELECT
event_id, namespace, event_time, op, acted_on
FROM events
WHERE event_time > 5"#,
)
.fetch(&mut pool)
.await
.unwrap();
Ok(())
}
-> "unknown field type ID: 2950"
I haven't seen any other errors like this, and my assumption is that sqlx doesn't support postgres UUIDs, but I'm not certain.
Could someone advise? If I can use statically typed sql queries, that would be a big win. We use UUIDs extensively from uuid-ossp
Thank you for reporting the issue.
We should support UUID (with the uuid feature) for Postgres but it doesn't look like we have an integration test for that type to prove it. Can you try enabling the feature and see if that allows it to work (we'll note a task to add an integration test for UUID support in any case).
# something like this
sqlx = { version = "0.1.1", features = [ "uuid" ] }
We do not support custom types at this time however. You'll need to do (something like) op::text in your SELECT ... in order to fetch the operation.
I had no idea this feature existed. I'll enable it when I get home and try it out. Thank you :D
That did it (the op::text too) thank you!
I might recommend a FAQ in the docs somewhere about enums and features for SQL and stuff and all that.
The library itself is great though. Thank you for all of the hard work!
Most helpful comment
Thank you for reporting the issue.
We should support UUID (with the
uuidfeature) for Postgres but it doesn't look like we have an integration test for that type to prove it. Can you try enabling the feature and see if that allows it to work (we'll note a task to add an integration test for UUID support in any case).We do not support custom types at this time however. You'll need to do (something like)
op::textin yourSELECT ...in order to fetch theoperation.