Closed a-agmon closed 1 year ago
Thanks for bringing this up. The problem is that you are checking for an error in
if err != nil {
t.Errorf("Error creating appender: %v", err)
}
but then you do not return and instead continue with the execution. Then in the next line
appender.Close()
you're trying to close the appender, but it isn't initialized because of the error that has been returned above.
Error creating appender: can't create appender
So the behaviour is intended. Please cancel the execution when receiving an error.
Thanks for the detailed reply @marcboeker . Apologies for not stating the issue correctly, Im trying to understand why there is a failure in creating the appender. I'm trying to figure out why this code would fail under my setup go1.21.0 darwin/arm64
package main
import (
"context"
"database/sql"
"log"
"github.com/marcboeker/go-duckdb"
)
func main() {
log.Println("Starting the application...")
c, err := duckdb.NewConnector("", nil)
if err != nil {
log.Fatalf("Error creating connector: %v", err)
}
db := sql.OpenDB(c)
defer db.Close()
conn, err := c.Connect(context.Background())
if err != nil {
log.Fatalf("Error creating connection: %v", err)
}
defer conn.Close()
appender, err := duckdb.NewAppenderFromConn(conn, "", "test")
if err != nil {
log.Fatalf("Error creating appender: %v", err)
}
appender.Close()
}
The appender you are creating requires a table called test
. This table does not exist in the example yet. Adding it via
res, err := db.Exec(`CREATE TABLE test (a INTEGER, b INTEGER)`)
fixes the problem.
Thanks @marcboeker - a small suggestion https://github.com/marcboeker/go-duckdb/pull/110
The following code - which is supposed to replicate the test in the repo, generates a fault. Would be grateful for advise if i'm doing something wrong here. Using GO 1.20.6 on MacOS (M1) ARM.