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

(Documentation) sqlx.In should be used with (?) instead of ($1) for postgres #959

Open
zachczx opened this issue Jan 4, 2025 · 0 comments

Comments

@zachczx
Copy link

zachczx commented Jan 4, 2025

Hello,

This is a note for people with similar problems in future. I used the sqlx.In helper with a postgres driver,

rows, err := db.Query("SELECT * FROM users WHERE level IN ($);", levels)

and kept getting an error

number of bindVars less than number arguments

I only had 1 bindVar so it was puzzling and it seemed correct because I had to use ($1) ($2) etc syntax for postgres.

But it turns out I had to use (?) instead of postgres syntax for bindVar.

So for anyone having this same error and using postgres (or think that doing it is correct), switch to (?) instead for the bindVars.

If it helps I'd be happy to do a PR to add this as a footnote to the user documentation.

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

1 participant