Rails - how to store large numbers like 100000076685963

前提是你 提交于 2019-12-30 10:38:49

问题


I need to store large numbers like :100000076685963

Which are to big for a db field type of integer. In my db migration I use:

  t.integer :fb_uid

what field type should I use for large numbers like this?

Thanks


回答1:


You can use a fixed-point datatype such as decimal with a large precision. Based on the number you've given, a precision of 15 will work but you should figure out exactly what range you are expecting.

t.decimal :fb_fluid, :precision => 15



回答2:


Try float

t.float :fb_uid

And seems like this is something to do with Facebook (probably facebooker) and assuming these numbers will not use as arithmetic operations, you could probably use just string

t.string :fb_uid



回答3:


You need to set the limit field in for the column to get Postgresql's bigint precision:

t.integer :fb_uid, limit: 8


来源:https://stackoverflow.com/questions/5919303/rails-how-to-store-large-numbers-like-100000076685963

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!