Convert BIGINT UNSIGNED to INT

后端 未结 3 1356
无人共我
无人共我 2021-02-13 07:21

I know it is unorthodox and potentially dangerous to want to convert something from a larger to a smaller sized data type. However, in this case, it is extremely unlikely that t

3条回答
  •  北海茫月
    2021-02-13 07:32

    this article seems to have a solution:

    Create the function that will perform the conversion:

    CREATE FUNCTION BigToInt (n BIGINT) RETURNS INTEGER RETURN n;

    As you can see, the function is very short and simple: It takes a BIGINT and immediately returns it as an ordinary integer. However, one consequence of this is that some of the data will be truncated down to the largest possible value for Int.

    (presumably you can add "UNSIGNED" to the signature - if not you can still combine it with the cast you already have that removes the unsigned part).

提交回复
热议问题