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
Unsupported type: nil when querying custom type in PostgreSQL #934
Comments
Hi @ivoras !
withNil := S{D: nil}
db.NewInsert().Model(&withNil).Exec(ctx) Scanning, on the other hand, is controlled by how (and if) the given type implements func (d *Date) Scan(value interface{}) (err error) {
switch v := value.(type) {
case []byte:
*d, err = ParseDate(RFC3339, string(v))
case string:
*d, err = ParseDate(RFC3339, v)
case time.Time:
*d = DateFromTime(v)
default:
err = fmt.Errorf("unsupported type %T", value)
}
return err
} the last part of the wrapped error message seems to come directly from here --
What do you do about it? You can wrap package ivorastime
type Date struct {
timex.Date
}
func (d *Date) Scan(value interface{}) (err error) {
if value != nil {
return d.Date.Scan(value)
}
// Optionally, since ivorastime.Date will initialize with zero timex.Date anyways:
// d.Date = timex.Date{}
return nil
}
Lines 81 to 83 in 8a43835
P.S.: specifying the language for your code snippets will add syntax highlighting:
instead of
|
I'm using timex.Date (https://github.com/invzhi/timex) to work with DATE fields in PostgreSQL, and I'm receiving en error when I try to load a null Date field (with the intent of it being loaded as the zero value in Go).
script:
The error produced is:
I'm not sure if it's a problem in Bun or in the timex.Date implementation, but it looks like a bug, especially since I have the
nullzero
annotation on the Date field.The text was updated successfully, but these errors were encountered: