You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to execute a SELECT query with the query_as! macro, the macro produces an error when the macro is used on a PostgreSQL table containing a column of type enum.
My understanding is that structs containing enums cannot be used with the query_as! macro and must instead be used with the query_as method. If this is the case a better error message containing something like, "cannot use query_as! macro with PostgreSQL custom types"
use serde::{Deserialize,Serialize};#[derive(sqlx::Type,Serialize,Deserialize,Debug)]#[sqlx(type_name = "status", rename_all = "lowercase")]pubenumStatus{Active,Inactive,Suspended}#[derive(sqlx::FromRow,Serialize,Deserialize,Debug)]pubstructTestEnum{pubid:Option<i32>,pubname:Option<String>,pubenum_col:Status,}let returned:Result<TestEnum,Error> = sqlx::query_as!(TestEnum,r#"SELECT id, name, enum_col FROM test_enum LIMIT 1"#).fetch_one(&pg).await;/*PostgreSQL:CREATE TYPE status AS ENUM ('active', 'inactive', 'suspended');CREATE TABLE test_enum ( id SERIAL PRIMARY KEY, name TEXT, enum_col status NOT NULL DEFAULT 'active');insert into test_enum (name) values ('test');*//*should produce this error:```basherror: unsupported type status of column #3 ("enum_col") --> src/routes/auth.rs:62:53 |62 | let returned: Result<TestEnum, Error> = sqlx::query_as!( | _____________________________________________________^63 | | TestEnum,64 | | r#"SELECT id, name, enum_col FROM test_enum LIMIT 1"#65 | | ) | |_____________^ | = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` (in Nightly builds, run with -Z macro-backtrace for more info)*/
Info
SQLx version: 0.7.1
SQLx features enabled: "postgres", "runtime-tokio", "chrono", "uuid", "macros"
Bug Description
When attempting to execute a
SELECT
query with thequery_as!
macro, the macro produces an error when the macro is used on a PostgreSQL table containing a column of type enum.My understanding is that structs containing enums cannot be used with the
query_as!
macro and must instead be used with thequery_as
method. If this is the case a better error message containing something like, "cannot usequery_as!
macro with PostgreSQL custom types"Minimal Reproduction
This gist is the main idea. You will have to add the proper imports and such, but the main idea is all here:
https://gist.github.com/HarrisonHemstreet/0d89f2a9bdd257d08a10b7e33c5600ae
Info
rustc --version
: rustc 1.69.0 (84c898d65 2023-04-16)The text was updated successfully, but these errors were encountered: