Skip to content

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

Open

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.

Activity

  1. suiriass commented on Jun 30, 2026

    @suiriass

    Good catch — this is a common stumbling block with sqlx.

    sqlex (https://github.com/go-sqlex/sqlex) handles this automatically: you write ? everywhere in your code, and it rebinds to the correct placeholder ($1, @p1, etc.) behind the scenes based on the database driver you're using. No need to think about which syntax to use. @zachczx

  2. TastyHeadphones commented on Sep 27, 2026

    @TastyHeadphones

    Opened a PR clarifying that sqlx.In always uses ? (then Rebind): #1003

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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