@@ -669,26 +669,14 @@ func mult(lval, rval interface{}) (interface{}, error) {
669669// UnaryMinus is an unary minus operator.
670670type UnaryMinus struct {
671671 UnaryExpression
672- typ sql.Type
673672}
674673
675674var _ sql.Expression = (* UnaryMinus )(nil )
676675var _ sql.CollationCoercible = (* UnaryMinus )(nil )
677676
678677// NewUnaryMinus creates a new UnaryMinus expression node.
679678func NewUnaryMinus (child sql.Expression ) * UnaryMinus {
680- typ := child .Type ()
681- switch child .Type () {
682- case types .Int8 , types .Int16 , types .Int32 :
683- typ = types .Int64
684- case types .Int64 :
685- if lit , ok := child .(* Literal ); ok {
686- if lit .Value ().(int64 ) == math .MinInt64 {
687- typ = types .InternalDecimalType
688- }
689- }
690- }
691- return & UnaryMinus {UnaryExpression {Child : child }, typ }
679+ return & UnaryMinus {UnaryExpression {Child : child }}
692680}
693681
694682// Eval implements the sql.Expression interface.
@@ -763,19 +751,31 @@ func (e *UnaryMinus) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
763751
764752// Type implements the sql.Expression interface.
765753func (e * UnaryMinus ) Type () sql.Type {
766- if ! types .IsNumber (e .typ ) {
754+ typ := e .Child .Type ()
755+ switch typ {
756+ case types .Int8 , types .Int16 , types .Int32 :
757+ typ = types .Int64
758+ case types .Int64 :
759+ if lit , ok := e .Child .(* Literal ); ok {
760+ if lit .Value ().(int64 ) == math .MinInt64 {
761+ typ = types .InternalDecimalType
762+ }
763+ }
764+ }
765+
766+ if ! types .IsNumber (typ ) {
767767 return types .Float64
768768 }
769769
770- if e . typ == types .Uint32 {
770+ if typ == types .Uint32 {
771771 return types .Int32
772772 }
773773
774- if e . typ == types .Uint64 {
774+ if typ == types .Uint64 {
775775 return types .Int64
776776 }
777777
778- return e . typ
778+ return typ
779779}
780780
781781// CollationCoercibility implements the interface sql.CollationCoercible.
0 commit comments