I am using following function inside my prepared statements for inserting NULL for zero values of type string and int64 but I can not find way to insert null when my []byte array is of zero length.
Golang Insert NULL into sql instead of empty string
// NewNullString converts empty string into db NULL
func NewNullString(s string) sql.NullString {
if len(s) == 0 {
return sql.NullString{}
}
return sql.NullString{
String: s,
Valid: true,
}
}
// NewNullInt64 converts 0 int64 into db NULL
func NewNullInt64(i int64) sql.NullInt64 {
if i == 0 {
return sql.NullInt64{}
}
return sql.NullInt64{
Int64: i,
Valid: true,
}
}