You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
After migrating from v4 to v5. Inserting or scanning custom defined uuid's stopped working.
To Reproduce
Steps to reproduce the behavior:
If possible, please provide runnable example such as:
package main
import (
"context""fmt""os""github.com/gofrs/uuid/v5"
pgxuuid "github.com/jackc/pgx-gofrs-uuid""github.com/jackc/pgx/v5""github.com/jackc/pgx/v5/pgxpool"
)
typeProviderID uuid.UUIDfuncmain() {
dbconfig, err:=pgxpool.ParseConfig(os.Getenv("DATABASE_URL"))
iferr!=nil {
fmt.Println("could not parse db config: ", err)
return
}
ctx:=context.Background()
dbconfig.AfterConnect=func(_ context.Context, conn*pgx.Conn) error {
pgxuuid.Register(conn.TypeMap())
returnnil
}
pool, err:=pgxpool.NewWithConfig(ctx, dbconfig)
iferr!=nil {
fmt.Println("could not create pool: ", err)
return
}
deferpool.Close()
_, err=pool.Exec(ctx, "CREATE TABLE IF NOT EXISTS test (id UUID PRIMARY KEY)")
iferr!=nil {
fmt.Println("could not create table: ", err)
return
}
_, err=pool.Exec(ctx, "INSERT INTO test (id) VALUES ($1)", ProviderID(uuid.Must(uuid.NewV4())))
iferr!=nil {
fmt.Println("could not insert value: ", err)
return
}
rows, err:=pool.Query(ctx, "SELECT id FROM test")
iferr!=nil {
fmt.Println("could not query: ", err)
return
}
deferrows.Close()
forrows.Next() {
varidProviderIDiferr:=rows.Scan(&id); err!=nil {
fmt.Println("could not scan: ", err)
return
}
fmt.Println("id: ", id)
}
}
Expected behavior
pgx should detect that the variable is an uuid and encode/decode it properly.
Actual behavior
It fails. When scanning this is the error:
could not scan: can't scan into dest[0]: cannot scan uuid (OID 2950) in binary format into *main.ProviderID
when inserting this is the error:
could not insert value: failed to encode args[0]: unable to encode main.ProviderID{0x84, 0x33, 0x6c, 0x48, 0x7, 0x10, 0x4a, 0xe2, 0x88, 0xc5, 0x49, 0xbb, 0xef, 0x7a, 0x3f, 0x30} into binary format for uuid (OID 2950): cannot find encode plan
However if I change the custom uuids by raw uuids, it works.
Version
Go: $ go version -> go version go1.21.5 darwin/arm64
Additional context
This represents a huge migration burden as the app contains more than 1.000 places where this needs to be fixed and I'm sure it's not uncommon.
The text was updated successfully, but these errors were encountered:
dfonnegra
changed the title
Cannot scan user defined UUIDs. failed to insert test framework providers: error inserting provider: can't scan into dest[0]: cannot scan uuid (OID 2950) in binary format into *myUUID
Cannot scan user defined UUIDs.
Aug 13, 2024
dfonnegra
changed the title
Cannot scan user defined UUIDs.
Cannot scan/insert user defined UUIDs.
Aug 13, 2024
Describe the bug
After migrating from v4 to v5. Inserting or scanning custom defined uuid's stopped working.
To Reproduce
Steps to reproduce the behavior:
If possible, please provide runnable example such as:
Expected behavior
pgx should detect that the variable is an uuid and encode/decode it properly.
Actual behavior
It fails. When scanning this is the error:
when inserting this is the error:
However if I change the custom uuids by raw uuids, it works.
Version
$ go version
-> go version go1.21.5 darwin/arm64$ grep 'github.com/jackc/pgx/v[0-9]' go.mod
-> github.com/jackc/pgx/v5 v5.6.0Additional context
This represents a huge migration burden as the app contains more than 1.000 places where this needs to be fixed and I'm sure it's not uncommon.
The text was updated successfully, but these errors were encountered: