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

Unable to bind Vec<Uuid> in postgres #1035

Closed
iamsiddhant05 opened this issue Feb 5, 2021 · 8 comments
Closed

Unable to bind Vec<Uuid> in postgres #1035

iamsiddhant05 opened this issue Feb 5, 2021 · 8 comments

Comments

@iamsiddhant05
Copy link
Contributor

First i tried binding this way, assuming sqlx will spread it on it's own, but it did not work

agent_id_list: Vec<Uuid>

...
WHERE agents.id IN ($1)
....

.bind(agent_id_list)
.fetch_all(pool)
.await?;

The I read on discord to try ANY

.......
WHERE agents.id = ANY($1)
......

But even this is not working!

I just want to know that the 2nd option requires spread as postgres array, Is something like this happening?

WHERE agents.id = ANY('{da338da4-a463-40d7-81d8-02519e211882, e02a61ba-7020-4b1c-bd9d-3d9e46c4c95e}')

How should i proceed here? Am I doing anything wrong?

@Kruptein
Copy link

Kruptein commented Feb 5, 2021

This seems to not be possible at the moment see #656, a workaround suggested in that topic is to use ($1) and agent_id_list.join(",")

@jplatte
Copy link
Contributor

jplatte commented Feb 5, 2021

But even this is not working!

"not working" is not a useful description of an error. What's the actual error message you get?

@iamsiddhant05
Copy link
Contributor Author

But even this is not working!

"not working" is not a useful description of an error. What's the actual error message you get?

Sorry, I did not post the error msg because i though it was weird, but then i ran the query by manually addind variable and it working fine.

Anyway this is the error msg from database:

"no column found for name: agent_id"

@jplatte
Copy link
Contributor

jplatte commented Feb 5, 2021

The SQL code you shared never uses the column name agent_id, only agents.id, so this problem seems related to a different part of the query. I'm fairly confident that error message has nothing to do with the = ANY($1) part.

@iamsiddhant05
Copy link
Contributor Author

I apologize, i just now found the issue. I was mapping to wrong struct and the issue was with the same key so i assumed it was because of the vector.

@iamsiddhant05
Copy link
Contributor Author

@jplatte Just a followup question will be I be able to use custom vectors with ANY ?

@iamsiddhant05
Copy link
Contributor Author

Something like this:

let suspended_status = vec![
    LeadStatus::Suspended,
    LeadStatus::Awaitingissuance,
    LeadStatus::Paidsuspended,
];
.....
.bind(suspended_status)
.fetch_all(pool)
.await?;

sqlx::Type has been added to LeadStatus.

@jplatte
Copy link
Contributor

jplatte commented Feb 5, 2021

Unfortunately that doesn't work, see #298.

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

3 participants