(Documentation) sqlx.In should be used with (?) instead of ($1) for postgres
Author: zachczxCreated Jan 4, 2025Updated Jun 30, 2026
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 argumentsI 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.
Source: jmoiron/sqlx