在mysql上需要大于20位的整数时该怎么办? [英] What to do when you need integers larger than 20 digits on mysql?

查看:1548
本文介绍了在mysql上需要大于20位的整数时该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎 BIGINT 是MySql上可用的最大整数,对吗?

Seems like BIGINT is the biggest integer available on MySql, right?

当你需要时该怎么办例如,存储BIGINT(80)?

What to do when you need to store a BIGINT(80) for example?

为什么在某些情况下,比如在Twitter API文档的某个地方,他们建议我们将这些大整数存储为 varchar

Why in some cases, like in somewhere in the Twitter API docs, they recommend us to store these large integers as varchar?

在这种情况下选择使用某种类型的真正原因是什么?

Which is the real reason behind the choice of using one type or another is this case?

推荐答案

大整数实际上并不限于20位,它们仅限于可用64位表示的数字(例如,数字 99,999,999,999,999,999,999 虽然长度为20位,但不是有效的大整数。)

Big integers aren't actually limited to 20 digits, they're limited to the numbers that can be expressed in 64 bits (for example, the number 99,999,999,999,999,999,999 is not a valid big integer despite it being 20 digits long).

你有这个的原因限制是底层硬件可以相对快速地操作本机格式整数,而一个数字(往往)的文本版本需要一次处理一个数字。

The reason you have this limitation is that native format integers can be manipulated relatively fast by the underlying hardware whereas textual versions of a number (tend to) need to be processed one digit at a time.

如果你想要一个更大的数字最大的64位无符号整数 18,446,744,073,709,551,615 然后您需要将其存储为 varchar (或其他文本字段)并且希望你不需要对它进行太多的数学操作。

If you want a number larger than the largest 64-bit unsigned integer 18,446,744,073,709,551,615 then you will need to store it as a varchar (or other textual field) and hope that you don't need to do much mathematical manipulation on it.

或者,您可以查看范围更大但精度更低的浮点数,或十进制数,应该能够为您提供65位数的整数值,十进制(65,0)作为列类型。

Alternatively, you can look into floating point numbers which have a larger range but less precision, or decimal numbers which should be able to give you 65 digits for an integral value, with decimal(65,0) as the column type.

这篇关于在mysql上需要大于20位的整数时该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆