-
Notifications
You must be signed in to change notification settings - Fork 573
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
expected ... arguments, got ... when using db.Prepare() #1485
Comments
Hello! Thanks for submitting an issue. For These lines have a good example (src): batch, err := tx.PrepareContext(ctx, "INSERT INTO go_json_example (product)")
if err != nil {
return err
}
insertProductString := "{\"id\":1234,\"name\":\"Book\",\"tags\":[\"library\",\"fiction\"]," +
"\"pricing\":{\"price\":750,\"currency\":\"usd\"},\"metadata\":{\"page_count\":852,\"region\":\"us\"}," +
"\"created_at\":\"2024-12-19T11:20:04.146Z\"}"
if _, err = batch.ExecContext(ctx, insertProductString); err != nil {
return err
} These are the Let me know if you're still having trouble, otherwise feel free to close this issue. Thanks! |
I'm not sure if I did it correctly because the example only has one column while I have multiple. I adjusted my code like this: stmt, err := db.Prepare(`INSERT INTO example(a, c)`)
if err != nil {
log.Fatalf("prepare failed: %w", err)
}
_, err = stmt.Exec("foo", "bar")
if err != nil {
log.Fatalf("execution failed: %w", err)
} To make it even closer to the example I also tried using a context and a transaction: ctx := context.Background()
tx, err := db.BeginTx(ctx, nil)
if err != nil {
log.Fatalf("begin failed: %w", err)
}
batch, err := tx.PrepareContext(ctx, `INSERT INTO example(a, c)`)
if err != nil {
log.Fatalf("prepare failed: %w", err)
}
_, err = batch.ExecContext(ctx, "foo", "bar")
if err != nil {
log.Fatalf("execution failed: %w", err)
}
err = tx.Commit()
if err != nil {
log.Fatalf("commit failed: %w", err)
} But in both cases I still get the same error:
|
Observed
The program below creates a table and tries to insert two rows into it. The first row is inserted using
db.Exec()
the second one usingstmt, err := db.Prepare()
+stmt.Exec()
.The insert using
db.Exec()
works, the insert usingstmt.Exec()
returns an error:expected 3 arguments, got 2
Expected behaviour
I'd expect both inserts to work identically.
Code example
Error log
Details
Environment
clickhouse-go
version: v2.30.1database/sql
compatible driverThe text was updated successfully, but these errors were encountered: