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

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

Closed
samber opened this issue Feb 4, 2021 · 5 comments
Closed

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

samber opened this issue Feb 4, 2021 · 5 comments

Comments

@samber
Copy link

samber commented Feb 4, 2021

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- sqlx@1.3.0 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?

@samber samber mentioned this issue Feb 4, 2021
@kgritesh
Copy link

Facing the same issue?

@pete-woods
Copy link

Another person suffering the same issue here

@gnuletik
Copy link

v1.3.3 seems to fix the issue :)

@jmoiron
Copy link
Owner

jmoiron commented May 15, 2021

If it wasn't fixed in v1.3.3, there's another fix for these types of issues in v1.3.4

@jmoiron jmoiron closed this as completed May 15, 2021
@0x457
Copy link

0x457 commented Dec 17, 2021

batch insert for support oracle? I got the same error

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants