diff --git a/clause/expression.go b/clause/expression.go index d0498306..dde00b1d 100644 --- a/clause/expression.go +++ b/clause/expression.go @@ -368,7 +368,7 @@ func (like Like) NegationBuild(builder Builder) { } func eqNil(value interface{}) bool { - if valuer, ok := value.(driver.Valuer); ok { + if valuer, ok := value.(driver.Valuer); ok && !eqNilReflect(valuer) { value, _ = valuer.Value() } diff --git a/statement.go b/statement.go index 453e485e..5a948d3f 100644 --- a/statement.go +++ b/statement.go @@ -173,7 +173,12 @@ func (stmt *Statement) AddVar(writer clause.Writer, vars ...interface{}) { case clause.Column, clause.Table: stmt.QuoteTo(writer, v) case Valuer: - stmt.AddVar(writer, v.GormValue(stmt.Context, stmt.DB)) + reflectValue := reflect.ValueOf(v) + if reflectValue.Kind() == reflect.Ptr && reflectValue.IsNil() { + stmt.AddVar(writer, nil) + } else { + stmt.AddVar(writer, v.GormValue(stmt.Context, stmt.DB)) + } case clause.Expr: v.Build(stmt) case *clause.Expr: