mac address insert error: SQLSTATE 22021
d0zer11st opened this issue · 1 comments
d0zer11st commented
postgres returns: ERROR: invalid byte sequence for encoding "UTF8": (SQLSTATE 22021)
On trying to insert record containing mac address.
how to reproduce:
- bob version: github.com/stephenafamo/bob v0.26.1
- postgres 16.2
- Table
create table example
(
id bigint primary key generated always as identity,
mac macaddr not null
)
- Trying to insert
db, openErr := sql.Open("pgx", connectionString)
if openErr != nil {
log.Fatal(openErr)
}
defer db.Close()
bobDB := bob.NewDB(db)
macToTest := "1b:1b:63:84:45:e6"
hwAddr, parseMacErr := net.ParseMAC(macToTest)
if parseMacErr != nil {
log.Fatal(parseMacErr)
}
log.Printf("parsed mac: %s", hwAddr)
omitMacValue := omit.From(
types.Stringer[net.HardwareAddr]{
Val: hwAddr,
},
)
exampleSetter := &models.ExampleSetter{
Mac: omitMacValue,
}
_, err := models.Examples.InsertMany(ctx, bobDB, exampleSetter)
if err != nil {
log.Fatal(err)
}
Generated models.ExampleSetter
// ExampleSetter is used for insert/upsert/update operations
// All values are optional, and do not have to be set
// Generated columns are not included
type ExampleSetter struct {
Mac omit.Val[types.Stringer[net.HardwareAddr]] `db:"mac"`
}
My assumption is something wrong with types.Stringer
returns []byte
Lines 72 to 74 in c4cf5c1
As well as it loads values.
Lines 76 to 89 in c4cf5c1
stephenafamo commented
I'll take a look