Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schema prefix for custom type caused fail for select and delete that prefix caused fail for insert in 0.7 #2595

Open
SuanCaiYv opened this issue Jul 7, 2023 · 1 comment · May be fixed by #2791
Labels

Comments

@SuanCaiYv
Copy link

PostgreSQL v15.
I have a db called prim, and there are two schemas called api and msg.

In api a enum type called user_status is defined, clearly, the full name is api.user_status, and the struct User has a field Status which has type UserStatus in Rust.

In sqlx 0.6, I use #sqlx(type_name = "user_status") as an attribute for type UserStatus in Rust code. and the select and insert operation refer to use api.user as full table name.

But in sqlx 0.7,
the insert raised an error says: 'type user_status' does not exist. , so I change the attribute for UserStatus to #[sqlx(type_name = "api.user_status")] and work well.
but select operation, an error called mismatched types; Rust type 'api::model::user::UserStatus' (as SQL type 'api.user_status') is not compatible with SQL type 'user_status' show there.

In sql statement to create table api.user, the type of column status is defined as api.user_status.

btw, in sqlx 0.6 select and insert has no error, but in sqlx 0.7, add schema prefix for custom type caused fail for select and delete that prefix caused fail for insert.

is that a bug?

image image image
@SuanCaiYv SuanCaiYv added the bug label Jul 7, 2023
@isobit
Copy link

isobit commented Jul 21, 2023

I'm also running into this; I believe it's an unintended consequence of ab2ae26, since $1::regtype::oid fails if the search path doesn't include the type. As you've discovered, fully qualifying the type name with the schema fixes that problem, but hits a bug with the custom type validation at query time: sqlx compares type names to validate custom types, but the OID lookup only gets the unqualified name of the type, not including the schema (namespace).

I'm working on a fix here but it's rather janky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants