package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/marcboeker/go-duckdb"
)
func main() {
db, err := sql.Open("duckdb", "")
if err != nil {
log.Fatalf("Failed to connect to DuckDB: %v\n", err)
}
defer db.Close()
_, err = db.Exec(`CREATE TABLE needle (vec FLOAT[3])`) // FLOAT[3] not FLOAT[]
if err != nil {
log.Fatalf("Failed to create table: %v\n", err)
}
_, err = db.Exec(`INSERT INTO needle VALUES (array[5, 5, 5]), (array[1, 1, 1])`)
if err != nil {
log.Fatalf("Failed to insert data: %v\n", err)
}
fmt.Println("Data inserted successfully.")
rows, err := db.Query(`SELECT * FROM needle`)
if err != nil {
log.Fatalf("Failed to query data: %v\n", err)
}
defer rows.Close()
fmt.Println("Query results:")
for rows.Next() {
var searchVec []float64
err := rows.Scan(&searchVec)
if err != nil {
log.Fatalf("Failed to scan row: %v\n", err)
}
fmt.Printf("vec: %v\n", searchVec)
}
if rows.Err() != nil {
log.Fatalf("Error during row iteration: %v\n", rows.Err())
}
}
go run main.go
Data inserted successfully.
Query results:
2024/11/24 10:58:57 Error during row iteration: database/sql/driver: unsupported data type: ARRAY: index: 0
exit status 1
================
Declaring table columns as float[] and float[3] results in different outcomes.
go run main.go Data inserted successfully. Query results: 2024/11/24 10:58:57 Error during row iteration: database/sql/driver: unsupported data type: ARRAY: index: 0 exit status 1
================ Declaring table columns as float[] and float[3] results in different outcomes.