Skip to content
Advertisement

How to negate integer value in MySQL 5.7?

I am performing a Select on 5.7.32 where I want to negate the values:

This results in the error:

How can this be overcome?

Advertisement

Answer

You can skip rows where it is out of range:

or you can just treat it as a string:

casting to signed will not work, since it will change values larger than 9223372036854775807 to be negative numbers, which when negated will be positive.

You could convert it back to a number with:

but that will lose precision for large numbers.

fiddle

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement