Skip to content

Prepared statements broken when using "Named" + "In" #695

@samber

Description

@samber

Hi @jmoiron and thanks for your work on this lib!

On the following example: http://jmoiron.github.io/sqlx/#namedParams, you show how to combine Named params and IN, in a single statement.

This is broken since -at least- [email protected] and on master branch.

Example with the following table:

CREATE TABLE (foo text, bar text);

The following code:

type Test struct {
  Foo string `db:"foo"`
  Bar string `db:"bar"`
}

test := []Test{
  {Foo: "hello", Bar: "world 1"},
  {Foo: "hello", Bar: "world 2"},
}

query := "INSERT INTO test (foo, bar) VALUES (:foo, :bar);"
query, args, err := sqlx.Named(, arg)
query, args, err := sqlx.In(query, args...)
query = db.Rebind(query)
_, err := db.Query(query, args...)

fmt.Println(err.Error())
// "pq: got 4 parameters but the statement requires 2"

fmt.Println(query)
// "INSERT INTO test (foo, bar) VALUES (?, ?);"
fmt.Println(args)
// [hello world 1 hello world 2]

Any idea?

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