BIGINT UNSIGNED value is out of range

前端 未结 7 968
不知归路
不知归路 2020-12-03 09:48

I am getting the error

BIGINT UNSIGNED value is out of range in \'(1301980250 - mydb.news_articles.date)\'

7条回答
  •  执笔经年
    2020-12-03 10:23

    Nobody mentionned that the log() function is only defined for strictly positive arguments. Watch for this when using substractions inside of log().

    As for the original question, a key factor for resolution was to tell us the data type for the date column. If it is UNSIGNED, MySQL might not like it.

    The rule is that MySQL has a poor arithmetic algo, and can't figure out how to substract an operand B FROM another A (= do A-B) when A is coded on less bytes than B AND B > A.

    e.g. A = 12 and is SMALLINT, B = 13 AS INT, then MySQL can't figure out what A-B is (-1 !)

    To make MySQL content, just expand the coding length of operand A. How? Using CAST(), or multiplying A by a decimal number.

    As one can see, it is less a problem of overflow than a problem of handling the sign in the arithmetics of MySQL. A microprocessor, or better, a human, has no problems to perform this kind of arithmetics...

    Using CAST() is the way, or for short, just provoke the implicit cast by multiplying operand A by 1. (or 1.0):

    e.g

    1.*A - B
    

提交回复
热议问题