Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving facebook id as int or varchar?

My question is more advisory than technical. I'm writing a Facebook app in which I am fetching some information about the user, including facebook_id.
I was wondering if I should keep the user id as INT or VARCHAR in the MySQL database?

like image 756
Sharon Haim Pour Avatar asked Aug 21 '11 12:08

Sharon Haim Pour


People also ask

Should ID be int or varchar?

An int is usually better, because it gives better performance. If your item has a natural key which is a varchar, you could use that and it will work. But you will get a performance improvement (and some other benefits) by adding a surrogate key that is an integer.

Are Facebook ids sequential?

Everyone on Facebook has a user ID number, created when they joined. The numbers aren't strictly sequential: the first few million are segmented by university, so that Harvard users were assigned 0-99999, Columbia users 100000-199999, Stanford users 200000-299999, and so on.

What is UID for Facebook?

Your User ID is a string of numbers that doesn't personally identify you but does connect to your Facebook profile. You have a User ID automatically, whether or not you choose to create a username. Learn how to find your user ID.


2 Answers

Facebook uses 64-bit integers (bigint) for their user ids. So you use Bigint UNSIGNED in MySQL.

"As a reminder, in the very near future, we will be rolling out 64 bit user IDs. We encourage you to test your applications by going to www.facebook.com/r.php?force_64bit and create test accounts with 64 bit UIDs."

Edit: Facebook usernames is not the same thing as the user id. The username is of course varchar but will not be returned as the id.

like image 51
Gustav Avatar answered Oct 04 '22 17:10

Gustav


Although unlikely, facebook could change the format of their ID's, so to make it future proof, I'd use a varchar.

like image 20
Rich S Avatar answered Oct 04 '22 18:10

Rich S