Skip to content

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

@zachczx

Description

@zachczx

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions