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

database/sql/driver: support slices? #16235

snadrus opened this issue Jul 1, 2016 · 7 comments

database/sql/driver: support slices? #16235

snadrus opened this issue Jul 1, 2016 · 7 comments


Copy link

snadrus commented Jul 1, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

  2. What operating system and processor architecture are you using (go env)?

  3. What did you do?

    db := ...connect to mysql db
    cursor, err := db.Query("SELECT * FROM user WHERE firstName IN (?)",
    []string{"Bob", "Matt", "Sam"})

    if err != nil { ////// Errored

  4. What did you expect to see?
    Comparing to PHP, I expected the following query's result:
    SELECT * FROM user WHERE firstName IN ('Bob', 'Matt', 'Sam')

  5. What did you see instead?
    sql: converting Exec argument #0's type: unsupported type []int, a slice

@ianlancetaylor ianlancetaylor changed the title MySQL: IN (?) cannot accept array database/sql/driver: default converter does not accept slices Jul 1, 2016
Copy link

CC @bradfitz

@bradfitz bradfitz added this to the Unplanned milestone Jul 1, 2016
@bradfitz bradfitz changed the title database/sql/driver: default converter does not accept slices database/sql/driver: support slices? Jul 1, 2016
Copy link

Related to #13567

Copy link

bradfitz commented Oct 9, 2016

Which database(s) support this at at the wire level? Where you send SQL with a single placeholder and an array type of values comes later?

Copy link

Postgresql is the main one I'm aware of, as it has native array types. MS SQL server can also support custom types that can included table valued types.

Copy link

bhcleek commented Dec 31, 2016

@kardianos Postgres and SQL Server (assuming the array is a custom table-valued type) would each treat that slice/array as a single scalar value. In the example given, firstName would have to be the array of names, not one of the names in the array. Postgres' array type, however, would allow ANY to match, assuming that the value was provided as an array (e.g. db.Query("SELECT * FROM user WHERE firstName = ANY (?)", pg.Array([]string{"Bob", "Matt", "Sam"})).

Copy link

CL mentions this issue.

gopherbot pushed a commit that referenced this issue May 18, 2017
Previously all arguments were passed through driver.IsValid.
This checked arguments against a few fundamental go types and
prevented others from being passed in as arguments.

The new interface driver.NamedValueChecker may be implemented
by both driver.Stmt and driver.Conn. This allows
this new interface to completely supersede the
driver.ColumnConverter interface as it can be used for
checking arguments known to a prepared statement and
arbitrary query arguments. The NamedValueChecker may be
skipped with driver.ErrSkip after all special cases are
exhausted to use the default argument converter.

In addition if driver.ErrRemoveArgument is returned
the argument will not be passed to the query at all,
useful for passing in driver specific per-query options.

Add a canonical Out argument wrapper to be passed
to OUTPUT parameters. This will unify checks that need to
be written in the NameValueChecker.

The statement number check is also moved to the argument
converter so the NamedValueChecker may remove arguments
passed to the query.

Fixes #13567
Fixes #18079
Updates #18417
Updates #17834
Updates #16235
Updates #13067
Updates #19797

Change-Id: I89088bd9cca4596a48bba37bfd20d987453ef237
Reviewed-by: Brad Fitzpatrick <>
Run-TryBot: Brad Fitzpatrick <>
TryBot-Result: Gobot Gobot <>
@bradfitz bradfitz modified the milestones: Go1.10, Go1.9 May 23, 2017
Copy link

@snadrus I think this is actually fixed. go1.9 now supports custom import types so it is now up to drivers to implement. Can you confirm?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

6 participants