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

Postgres: Cannot pass array of enum as bind argument #1437

Closed
FallenWarrior2k opened this issue Sep 13, 2021 · 2 comments
Closed

Postgres: Cannot pass array of enum as bind argument #1437

FallenWarrior2k opened this issue Sep 13, 2021 · 2 comments

Comments

@FallenWarrior2k
Copy link

I have this enum:

#[derive(Debug, sqlx::Type)]
#[sqlx(type_name = "state", rename_all = "snake_case")]
pub enum State {
    Open,
    Closed,
    Canceled,
    TimedOut
}

I wanted to pass a Vec<State> into a query to filter against several options. I've tried using both join unnest($1::state[]) state using (state) and = any($1::state[]), but I don't think it makes any difference.
If I try to pass it directly, the compiler complains that Vec<State>: !Type<Postgres>, so I looked at the docs to see if there's alternatives and found the impl for Vec<(T,)>, so I tried with Vec<(State,)>, but that errors because (State,): !Encode<'_, Postgres>.

For now, my solution is to map the enum variants to &'static str before passing them in.

@jplatte
Copy link
Contributor

jplatte commented Sep 13, 2021

Duplicate of #298, will be fixed by #1385.

@FallenWarrior2k
Copy link
Author

FallenWarrior2k commented Sep 13, 2021

Ah, my bad, I was searching specifically for enum when looking for potential duplicates.
Must've overlooked that one because of the title because it does mention enums in the body text, now that I look at it.

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

No branches or pull requests

2 participants