diff --git a/README.md b/README.md index c254af6..a11a0c0 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ In addition to the [API documentation](https://pkg.go.dev/github.com/secondwindo there is also upstream's [user guide](https://jmoiron.github.io/sqlx/) that explains how to use `database/sql` along with sqlx. +`sqlx.In` always expands with `?` placeholders. Even on PostgreSQL, write +`IN (?)` (not `IN ($1)`), then `db.Rebind` the query before running it. + ## About this fork This is a maintained fork of [jmoiron/sqlx](https://github.com/jmoiron/sqlx). diff --git a/bind.go b/bind.go index f597184..ec25f3b 100644 --- a/bind.go +++ b/bind.go @@ -137,8 +137,13 @@ func asSliceForIn(i interface{}) (v reflect.Value, ok bool) { } // In expands slice values in args, returning the modified query string -// and a new arg list that can be executed by a database. The `query` should -// use the `?` bindVar. The return value uses the `?` bindVar. +// and a new arg list that can be executed by a database. +// +// The query must use the `?` bindVar (not `$1`, `@p1`, etc.), even when +// targeting PostgreSQL or other drivers that normally use a different +// placeholder style. In always returns a query that still uses `?`; call +// db.Rebind on the result before Query/Exec so the placeholders match the +// driver. func In(query string, args ...interface{}) (string, []interface{}, error) { // argMeta stores reflect.Value and length for slices and // the value itself for non-slice arguments